Skip to content

Commit

Permalink
clean.go: detect more license files
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed Feb 16, 2017
1 parent f1f3343 commit f77ece9
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions clean.go
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"sort"
"strings"

Expand Down Expand Up @@ -53,12 +54,8 @@ func isGoFile(path string) bool {
return ext == ".go" || ext == ".c" || ext == ".h" || ext == ".s" || ext == ".proto"
}

var licenseFiles = map[string]bool{
"LICENSE": true,
"COPYING": true,
"PATENTS": true,
"NOTICE": true,
}
// licenseFilesRegexp is a regexp of file names that are likely to contain licensing information
var licenseFilesRegexp = regexp.MustCompile(`(?i).*(LICENSE|COPYING|PATENT|NOTICE|README).*`)

// cleanVendor removes files from unused pacakges and non-go files
func cleanVendor(vendorDir string, realDeps []*build.Package) error {
Expand Down Expand Up @@ -92,7 +89,7 @@ func cleanVendor(vendorDir string, realDeps []*build.Package) error {
}

// keep files for licenses
if licenseFiles[i.Name()] {
if licenseFilesRegexp.MatchString(i.Name()) {
return nil
}
// remove files from non-deps, non-go files and test files
Expand All @@ -115,7 +112,7 @@ func cleanVendor(vendorDir string, realDeps []*build.Package) error {
// remove licenses if it's only files
var onlyLicenses = true
for _, fi := range lst {
if !licenseFiles[fi.Name()] {
if !licenseFilesRegexp.MatchString(fi.Name()) {
onlyLicenses = false
break
}
Expand Down

0 comments on commit f77ece9

Please sign in to comment.