diff options
Diffstat (limited to 'report.go')
| -rw-r--r-- | report.go | 52 |
1 files changed, 37 insertions, 15 deletions
@@ -26,6 +26,7 @@ const ( reportGroupRegular = `regular` reportGroupBinary = `binary` reportGroupUnknown = `unknown` + reportGroupDone = `done` ) // v1FieldsPerRecord fixed number of columns in report. @@ -35,6 +36,17 @@ type report struct { listBinary map[string]*file listRegular map[string]*file listUnknown map[string]*file + listDone map[string]*file +} + +func newReport() (rep *report) { + rep = &report{ + listBinary: map[string]*file{}, + listRegular: map[string]*file{}, + listUnknown: map[string]*file{}, + listDone: map[string]*file{}, + } + return rep } // loadReport load the [ReportFile] from the current directory. @@ -64,12 +76,11 @@ func loadReport() (rep *report, err error) { if !strings.HasPrefix(record[0], reportMetaPrefix) { goto next } - group = strings.TrimPrefix(record[0], reportMetaPrefix) - switch group { - case reportGroupRegular, reportGroupBinary, reportGroupUnknown: - // OK - default: - group = `` + tmpGroup := strings.TrimPrefix(record[0], reportMetaPrefix) + switch tmpGroup { + case reportGroupRegular, reportGroupBinary, + reportGroupUnknown, reportGroupDone: + group = tmpGroup } goto next } @@ -100,6 +111,8 @@ func loadReport() (rep *report, err error) { case reportGroupUnknown: f.group = groupUnknown rep.listUnknown[f.path] = f + case reportGroupDone: + rep.listDone[f.path] = f } next: record, err = csvr.Read() @@ -109,21 +122,17 @@ func loadReport() (rep *report, err error) { return rep, nil } -func newReport() (rep *report) { - rep = &report{ - listBinary: map[string]*file{}, - listRegular: map[string]*file{}, - listUnknown: map[string]*file{}, - } - return rep -} - func (rep *report) scan(conv *SPDXConv, listFile []string) (err error) { var logp = `report.scan` + var ok bool for _, file := range listFile { if rep.hasScanned(file) { continue } + _, ok = rep.listDone[file] + if ok { + continue + } f, err := newFile(file, conv.cfg.MaxLineMatch) if err != nil { @@ -145,6 +154,7 @@ func (rep *report) scan(conv *SPDXConv, listFile []string) (err error) { continue } if f.licenseID == valExist && f.copyrightText == valExist { + rep.listDone[f.path] = f continue } if f.copyrightYear == `` { @@ -223,6 +233,18 @@ func (rep *report) write() (err error) { } csvw.Flush() + buf.WriteString("//\n") + buf.WriteString(reportMetaPrefix + reportGroupDone + "\n") + buf.WriteString("//\n") + for _, key := range slices.Sorted(maps.Keys(rep.listDone)) { + f = rep.listDone[key] + err = csvWrite(csvw, f, record) + if err != nil { + return err + } + } + csvw.Flush() + err = os.WriteFile(ReportFile, buf.Bytes(), 0600) if err != nil { return err |
