summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-15 14:39:39 +0700
committerShulhan <ms@kilabit.info>2026-01-15 14:39:39 +0700
commit9be132113a261309f73aaddbb83af898a88db385 (patch)
tree6b59878c46a3d5ee106b7aaba8b9bea5c2eae032
parente662e3bc3c4aadf15a360495deaa86939ce84980 (diff)
downloadspdxconv-9be132113a261309f73aaddbb83af898a88db385.tar.xz
all: move checking REUSE annotation after all files listed
Use case: on the first scan, the file result in group unknown. User then modify the spdxconv.cfg to add or update the match-file-pattern. The next scan should check again the files in unknown group, in case its match with updated config.
-rw-r--r--report.go36
-rw-r--r--report_test.go11
-rw-r--r--spdxconv.go3
-rw-r--r--spdxconv_test.go4
-rw-r--r--testdata/Apply_test.txt8
5 files changed, 30 insertions, 32 deletions
diff --git a/report.go b/report.go
index 64720b3..6a38f8d 100644
--- a/report.go
+++ b/report.go
@@ -109,8 +109,10 @@ func loadReport() (rep *report, err error) {
f.group = groupBinary
rep.listBinary[f.path] = f
case reportGroupUnknown:
- f.group = groupUnknown
- rep.listUnknown[f.path] = f
+ // Don't store it, we may need to rescan it later.
+ // Use case: the first scan result in unknown, user
+ // then modify the match-file-pattern and re-scan
+ // again.
case reportGroupDone:
rep.listDone[f.path] = f
}
@@ -124,21 +126,28 @@ func loadReport() (rep *report, err error) {
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) {
+ for _, path := range listFile {
+ if rep.hasScanned(path) {
continue
}
- _, ok = rep.listDone[file]
- if ok {
+ // User may update the REUSE.toml on next scan.
+ if conv.reuse != nil && conv.reuse.isAnnotated(path) {
+ rep.listDone[path] = &file{
+ path: path,
+ }
continue
}
-
- f, err := newFile(file, conv.cfg.MaxLineMatch)
+ f, err := newFile(path, conv.cfg.MaxLineMatch)
if err != nil {
return fmt.Errorf(`%s: %w`, logp, err)
}
if f.group == groupBinary {
+ f.licenseID = valDefault
+ f.copyrightText = valDefault
+ f.getYearFromSCM(conv)
+ if f.copyrightYear == `` {
+ f.copyrightYear = conv.cfg.CopyrightYear
+ }
rep.listBinary[f.path] = f
continue
}
@@ -166,8 +175,8 @@ func (rep *report) scan(conv *SPDXConv, listFile []string) (err error) {
return nil
}
-// hasScanned return true if the file is already reported in regular or
-// binary group before.
+// hasScanned return true if the file is already reported in regular, binary,
+// or done group before.
func (rep *report) hasScanned(path string) bool {
var ok bool
_, ok = rep.listBinary[path]
@@ -178,7 +187,10 @@ func (rep *report) hasScanned(path string) bool {
if ok {
return true
}
- delete(rep.listUnknown, path)
+ _, ok = rep.listDone[path]
+ if ok {
+ return true
+ }
return false
}
diff --git a/report_test.go b/report_test.go
index fc8ea65..e77901d 100644
--- a/report_test.go
+++ b/report_test.go
@@ -53,15 +53,8 @@ func TestLoadReport(t *testing.T) {
group: groupBinary,
},
},
- listUnknown: map[string]*file{
- `fileU1`: &file{
- path: `fileU1`,
- licenseID: valDefault,
- copyrightText: valDefault,
- group: groupUnknown,
- },
- },
- listDone: map[string]*file{},
+ listUnknown: map[string]*file{},
+ listDone: map[string]*file{},
}
test.Assert(t, workDir, exp, got)
}
diff --git a/spdxconv.go b/spdxconv.go
index a5c8545..58f199d 100644
--- a/spdxconv.go
+++ b/spdxconv.go
@@ -331,9 +331,6 @@ func (conv *SPDXConv) scanDir(listDir []string) (listFile []string, err error) {
if conv.scm.IsIgnored(relpath) {
continue
}
- if conv.reuse != nil && conv.reuse.isAnnotated(relpath) {
- continue
- }
if de.IsDir() {
listDir = append(listDir, relpath)
continue
diff --git a/spdxconv_test.go b/spdxconv_test.go
index 6c33645..84b3718 100644
--- a/spdxconv_test.go
+++ b/spdxconv_test.go
@@ -163,6 +163,8 @@ test.json,default,0,2026,default,0,,
//
.gitignore,exist,0,,exist,1,#,
a/b/.gitignore,exist,0,,exist,1,#,
+po/test.po,,0,,,0,,
+po/test.pot,,0,,,0,,
with_spdx.go,exist,0,,exist,1,//,
`
@@ -360,6 +362,8 @@ func TestSPDXConv_scanDir(t *testing.T) {
`go.sum`,
`no_copyright_year.md`,
`po/included.go`,
+ `po/test.po`,
+ `po/test.pot`,
`test.go`,
`test.html`,
`test.json`,
diff --git a/testdata/Apply_test.txt b/testdata/Apply_test.txt
index b643a3c..a6723e2 100644
--- a/testdata/Apply_test.txt
+++ b/testdata/Apply_test.txt
@@ -76,14 +76,6 @@ delete_line_after = "^(//+|#+|\\*+/|--+>|--+)$"
//
//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
//