aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spdxconv.go27
-rw-r--r--testdata/loadConfig/config_exists/spdxconv.cfg2
-rw-r--r--testdata/scan/dummy2
-rw-r--r--testdata/scan/dummy.license2
4 files changed, 29 insertions, 4 deletions
diff --git a/spdxconv.go b/spdxconv.go
index 7222eb4..b303070 100644
--- a/spdxconv.go
+++ b/spdxconv.go
@@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
+ "slices"
"strings"
"git.sr.ht/~shulhan/pakakeh.go/lib/git"
@@ -70,6 +71,7 @@ func New(path string) (conv *SPDXConv, err error) {
}
conv = &SPDXConv{}
+
conv.curDir, err = os.Getwd()
if err != nil {
return nil, fmt.Errorf(`%s: %w`, logp, err)
@@ -179,6 +181,8 @@ func (conv *SPDXConv) scanFiles(listDir []string) (listFile []string, err error)
`node_modules`: struct{}{},
`vendor`: struct{}{},
}
+ var suffixLicense = `.license`
+
var dir string
var listde []os.DirEntry
var de os.DirEntry
@@ -191,8 +195,17 @@ func (conv *SPDXConv) scanFiles(listDir []string) (listFile []string, err error)
if err != nil {
return listFile, err
}
+
+ var listFileLicense = make(map[string]struct{})
+ var listName []string
for _, de = range listde {
var name = de.Name()
+ // File end with ".license" is SPDX specific file that
+ // contains only identifiers.
+ if strings.HasSuffix(name, suffixLicense) {
+ listFileLicense[name] = struct{}{}
+ continue
+ }
if conv.scm.IsIgnored(name) {
continue
}
@@ -200,12 +213,20 @@ func (conv *SPDXConv) scanFiles(listDir []string) (listFile []string, err error)
if ok {
continue
}
- var pathName = filepath.Join(dir, name)
+ listName = append(listName, name)
+ name = filepath.Join(dir, name)
if de.IsDir() {
- listDir = append(listDir, pathName)
+ listDir = append(listDir, name)
continue
}
- listFile = append(listFile, pathName)
+ listFile = append(listFile, name)
+ }
+ // Remove the file that have the spdx .license file.
+ for x, name := range listName {
+ _, ok = listFileLicense[name+suffixLicense]
+ if ok {
+ listFile = slices.Delete(listFile, x, x+1)
+ }
}
}
return listFile, nil
diff --git a/testdata/loadConfig/config_exists/spdxconv.cfg b/testdata/loadConfig/config_exists/spdxconv.cfg
index e4edf89..669d38a 100644
--- a/testdata/loadConfig/config_exists/spdxconv.cfg
+++ b/testdata/loadConfig/config_exists/spdxconv.cfg
@@ -11,4 +11,4 @@ delete_line_pattern = "^(//+|#+)*\\s*$"
delete_line_pattern = "^(//+|#+)*\\s+license that(.*)$"
[match-copyright]
-pattern = "^(//+|#+)*\\s+Copyright\\s+(?<year>\\d{4},?\\s+(?<holder>.*)\\s+<*(?<email>.*)>.*$"
+pattern = "^(//+|#+)*\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<holder>.*)\\s+<*(?<email>.*)>.*$"
diff --git a/testdata/scan/dummy b/testdata/scan/dummy
new file mode 100644
index 0000000..73fd7c8
--- /dev/null
+++ b/testdata/scan/dummy
@@ -0,0 +1,2 @@
+// SPDX-License-Identifier: GPL-3.0-only
+// SPDX-FileCopyrightText: 2025 M. Shulhan <ms@kilabit.info>
diff --git a/testdata/scan/dummy.license b/testdata/scan/dummy.license
new file mode 100644
index 0000000..73fd7c8
--- /dev/null
+++ b/testdata/scan/dummy.license
@@ -0,0 +1,2 @@
+// SPDX-License-Identifier: GPL-3.0-only
+// SPDX-FileCopyrightText: 2025 M. Shulhan <ms@kilabit.info>