diff options
| author | Shulhan <ms@kilabit.info> | 2026-01-07 14:36:59 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2026-01-07 14:36:59 +0700 |
| commit | 161049a3996c574d521d6d3df55998028eb111c0 (patch) | |
| tree | 5fbd77bdd7910dcead3568a9bfabf18515bfa14c | |
| parent | 08a4462c66fab99e5e66b465f053291c438dd0e0 (diff) | |
| download | spdxconv-161049a3996c574d521d6d3df55998028eb111c0.tar.xz | |
all: exclude file that have ".license" file
If the file X has another file named "X.license" in the same directory,
exclude it for being processed.
The ".license" is SPDX specific file that contains only SPDX identifiers.
| -rw-r--r-- | spdxconv.go | 27 | ||||
| -rw-r--r-- | testdata/loadConfig/config_exists/spdxconv.cfg | 2 | ||||
| -rw-r--r-- | testdata/scan/dummy | 2 | ||||
| -rw-r--r-- | testdata/scan/dummy.license | 2 |
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> |
