aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md10
-rw-r--r--file.go1
-rw-r--r--report.go52
-rw-r--r--report_test.go1
-rw-r--r--spdxconv.go2
-rw-r--r--spdxconv_test.go6
-rw-r--r--testdata/Apply_test.txt39
7 files changed, 92 insertions, 19 deletions
diff --git a/README.md b/README.md
index 436b8ab..33aad96 100644
--- a/README.md
+++ b/README.md
@@ -359,7 +359,7 @@ used as comment in the file.
#### spdxconv.report file groups
Each file in the report file is collected into three groups: regular,
-binary, and unknown files.
+binary, unknown, done files.
Each group is separated by line prefixed with "//spdxconv:" and its
identifier,
@@ -370,6 +370,8 @@ identifier,
...
//spdxconv:unknown
...
+//spdxconv:done
+...
```
Regular group are list of file where program can detect its file comment to
@@ -389,6 +391,9 @@ to be used.
This files will not be processed, it is listed here so user can inspect,
modify the configuration, and rerun the scan command for the next cycle.
+Done group are list of file that already has SPDX identifiers.
+File in regular and binary group that has been applied will be moved here.
+
### apply command
The apply command read the "spdxconv.report" and apply the license and
@@ -396,8 +401,7 @@ copyright in the file as stated on each line in the report.
Any failed operation on file will be logged to stdout.
-Once completed, it will write back the report file but only contains line
-that cannot be processed.
+Once completed, it will write back the report file.
## References
diff --git a/file.go b/file.go
index c5f2c79..80780d1 100644
--- a/file.go
+++ b/file.go
@@ -29,7 +29,6 @@ const (
groupRegular = 0
groupBinary = 1
groupUnknown = 2
- groupApplied = 3
)
// REUSE-IgnoreStart
diff --git a/report.go b/report.go
index d8acc0c..7f7320b 100644
--- a/report.go
+++ b/report.go
@@ -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
diff --git a/report_test.go b/report_test.go
index a042652..fc8ea65 100644
--- a/report_test.go
+++ b/report_test.go
@@ -61,6 +61,7 @@ func TestLoadReport(t *testing.T) {
group: groupUnknown,
},
},
+ listDone: map[string]*file{},
}
test.Assert(t, workDir, exp, got)
}
diff --git a/spdxconv.go b/spdxconv.go
index 64f138f..a5c8545 100644
--- a/spdxconv.go
+++ b/spdxconv.go
@@ -133,6 +133,7 @@ func Apply() (err error) {
log.Printf(`%s: %s`, logp, err)
continue
}
+ rep.listDone[f.path] = f
}
rep.listRegular = listFail
@@ -151,6 +152,7 @@ func Apply() (err error) {
log.Printf(`%s: failed to write %s`, logp, pathLicense)
continue
}
+ rep.listDone[f.path] = f
}
rep.listBinary = listFail
diff --git a/spdxconv_test.go b/spdxconv_test.go
index a0afc18..85a5cf2 100644
--- a/spdxconv_test.go
+++ b/spdxconv_test.go
@@ -147,6 +147,12 @@ test.json,default,0,2026,default,0,,
//
//spdxconv:unknown
//
+//
+//spdxconv:done
+//
+.gitignore,exist,0,,exist,1,#,
+a/b/.gitignore,exist,0,,exist,1,#,
+with_spdx.go,exist,0,,exist,1,//,
`
test.Assert(t, `Scan: `+scanDir, exp, string(got))
diff --git a/testdata/Apply_test.txt b/testdata/Apply_test.txt
index 13ee6be..b643a3c 100644
--- a/testdata/Apply_test.txt
+++ b/testdata/Apply_test.txt
@@ -59,6 +59,45 @@ pattern = "^(//+|#+|/\\*+|<!--+|--+)?\\s*Copyright\\s+(?<year>\\d{4}),?\\s+(?<au
delete_line_before = "^(//+|#+|/\\*+|<!--+|--+)$"
delete_line_after = "^(//+|#+|\\*+/|--+>|--+)$"
+>>> spdxconv.report
+
+<<< spdxconv.report
+// SPDX-License-Identifier: CC0-1.0
+// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info>
+
+//spdxconv:version:v1
+//spdxconv:header:path,license_id,idx_license_id,year,copyright_id,idx_copyright_id
+//
+//spdxconv:regular
+//
+//
+//spdxconv:binary
+//
+//
+//spdxconv:unknown
+//
+with_match_license.txt,,0,,,0,,
+with_match_license_bottom.txt,,0,,,0,,
+with_no_order.txt,,0,,,0,,
+with_spdx.txt,,0,,,0,,
+with_spdx_at_bottom.txt,,0,,,0,,
+with_spdx_license_id_only.txt,,0,,,0,,
+with_spdx_no_order.txt,,0,,,0,,
+without_spdx_license_id.txt,,0,,,0,,
+//
+//spdxconv:done
+//
+.gitignore,exist,0,,exist,1,#,
+empty.html,GPL-3.0-only,0,2026,M. Shulhan <ms@kilabit.info>,0,<!--,-->
+with.html,BSD-3-Clause,0,2022,Shulhan <ms@kilabit.info>,1,<!--,-->
+with_match_license.go,BSD-3-Clause,0,2018,Shulhan <ms@kilabit.info>,0,//,
+with_match_license_bottom.go,BSD-3-Clause,0,2018,Shulhan <ms@kilabit.info>,4,//,
+with_spdx.go,exist,0,,exist,1,//,
+with_spdx_at_bottom.go,GPL-3.0-only,0,2026,M. Shulhan <ms@kilabit.info>,0,//,
+with_spdx_license_id_only.go,GPL-3.0-only,0,2026,M. Shulhan <ms@kilabit.info>,0,//,
+with_spdx_no_order.go,exist,1,,exist,0,//,
+without_spdx_license_id.go,GPL-3.0-only,0,2026,M. Shulhan <ms@kilabit.info>,0,//,
+
>>> empty.html
<<< empty.html