aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--file.go26
-rw-r--r--report.go10
-rw-r--r--report_test.go4
-rw-r--r--spdxconv_test.go2
4 files changed, 25 insertions, 17 deletions
diff --git a/file.go b/file.go
index 0ac312a..c5f2c79 100644
--- a/file.go
+++ b/file.go
@@ -25,6 +25,13 @@ const (
valMatch = `match` // One of the pattern in match-xxx found in file.
)
+const (
+ groupRegular = 0
+ groupBinary = 1
+ groupUnknown = 2
+ groupApplied = 3
+)
+
// REUSE-IgnoreStart
// reLicenseID regex to detect SPDX license identifier with or without
@@ -64,9 +71,10 @@ type file struct {
// "exist:".
idxCopyrightText int
+ // group of file: regular (0), binary, unknown, or applied.
+ group int
+
hasSheBang bool
- isBinary bool // True if file is binary.
- isUnknown bool // True if file is regular with unknown comment.
}
func newFile(path string, maxLine int) (f *file, err error) {
@@ -77,10 +85,10 @@ func newFile(path string, maxLine int) (f *file, err error) {
}
f = &file{
- path: path,
- isBinary: libos.IsBinaryStream(content),
+ path: path,
}
- if f.isBinary {
+ if libos.IsBinaryStream(content) {
+ f.group = groupBinary
return f, nil
}
@@ -120,7 +128,7 @@ func (f *file) initLines(content []byte, maxLine int) (err error) {
func (f *file) scan(conv *SPDXConv) {
f.detectComment(&conv.cfg)
- if f.isBinary {
+ if f.group == groupBinary {
f.licenseID = valDefault
f.copyrightText = valDefault
f.getYearFromSCM(conv)
@@ -129,7 +137,7 @@ func (f *file) scan(conv *SPDXConv) {
}
return
}
- if f.isUnknown {
+ if f.group == groupUnknown {
return
}
f.scanLicenseID(conv)
@@ -147,7 +155,7 @@ func (f *file) detectComment(cfg *config) {
for _, mfc := range cfg.MatchFileComment {
if mfc.rePattern.MatchString(basename) {
if mfc.isDirectLicense() {
- f.isBinary = true
+ f.group = groupBinary
return
}
f.commentPrefix = mfc.Prefix
@@ -155,7 +163,7 @@ func (f *file) detectComment(cfg *config) {
return
}
}
- f.isUnknown = true
+ f.group = groupUnknown
}
func (f *file) scanLicenseID(conv *SPDXConv) {
diff --git a/report.go b/report.go
index b33149a..df77fa6 100644
--- a/report.go
+++ b/report.go
@@ -93,10 +93,10 @@ func loadReport() (rep *report, err error) {
case reportGroupRegular:
rep.listRegular = append(rep.listRegular, f)
case reportGroupBinary:
- f.isBinary = true
+ f.group = groupBinary
rep.listBinary = append(rep.listBinary, f)
case reportGroupUnknown:
- f.isUnknown = true
+ f.group = groupUnknown
rep.listUnknown = append(rep.listUnknown, f)
}
next:
@@ -119,18 +119,18 @@ func (rep *report) scan(conv *SPDXConv, listFile []string) (err error) {
if err != nil {
return fmt.Errorf(`%s: %w`, logp, err)
}
- if f.isBinary {
+ if f.group == groupBinary {
rep.listBinary = append(rep.listBinary, f)
continue
}
f.scan(conv)
- if f.isBinary {
+ if f.group == groupBinary {
// json file should be detected as binary, since its
// does not have comment syntax.
rep.listBinary = append(rep.listBinary, f)
continue
}
- if f.isUnknown {
+ if f.group == groupUnknown {
rep.listUnknown = append(rep.listUnknown, f)
continue
}
diff --git a/report_test.go b/report_test.go
index 2b31436..abe7766 100644
--- a/report_test.go
+++ b/report_test.go
@@ -45,13 +45,13 @@ func TestLoadReport(t *testing.T) {
path: `fileB1`,
licenseID: valDefault,
copyrightText: valDefault,
- isBinary: true,
+ group: groupBinary,
}},
listUnknown: []*file{{
path: `fileU1`,
licenseID: valDefault,
copyrightText: valDefault,
- isUnknown: true,
+ group: groupUnknown,
}},
}
test.Assert(t, workDir, exp, got)
diff --git a/spdxconv_test.go b/spdxconv_test.go
index 5186504..a0afc18 100644
--- a/spdxconv_test.go
+++ b/spdxconv_test.go
@@ -143,7 +143,7 @@ test.sql,match,1,2022,match,0,--,
//
//spdxconv:binary
//
-test.json,default,0,2025,default,0,,
+test.json,default,0,2026,default,0,,
//
//spdxconv:unknown
//