fix(healthcheck/nonasciifile): comment, code style and check range
This commit is contained in:
parent
373d31cb5c
commit
68e4c8e01e
|
@ -43,12 +43,12 @@ func main() {
|
||||||
showVersion := flag.Bool("version", false, "print current version")
|
showVersion := flag.Bool("version", false, "print current version")
|
||||||
rootDir := flag.String("root", ".", "root dir for forbidden files check")
|
rootDir := flag.String("root", ".", "root dir for forbidden files check")
|
||||||
repoSize := flag.Float64("repoSize", 2, "maximum size of the repo in MiB")
|
repoSize := flag.Float64("repoSize", 2, "maximum size of the repo in MiB")
|
||||||
// TODO: remove gitWhitelist, it is only for backward compatibility now
|
// TODO: remove git whitelist, it is only for backward compatibility now
|
||||||
localList := flag.String("localList", "", "local file list for non-ascii file check")
|
localList := flag.String("localList", "", "local file list for non-ascii file check")
|
||||||
checkFileNameList := flag.String("checkFileNameList", "", "comma-separated list of files to check")
|
checkFileNameList := flag.String("checkFileNameList", "", "comma-separated list of files to check")
|
||||||
checkFileSumList := flag.String("checkFileSumList", "", "comma-separated list of expected checksums")
|
checkFileSumList := flag.String("checkFileSumList", "", "comma-separated list of expected checksums")
|
||||||
parseMultiValueFlag(&metaFile, "meta", "meta files to check")
|
parseMultiValueFlag(&metaFile, "meta", "meta files to check")
|
||||||
// TODO: remove gitWhitelist, it is only for backward compatibility now
|
// TODO: remove git whitelist, it is only for backward compatibility now
|
||||||
var gitWhitelist []string
|
var gitWhitelist []string
|
||||||
parseMultiValueFlag(&gitWhitelist, "whitelist", "[DEPRECATED] will be ignored")
|
parseMultiValueFlag(&gitWhitelist, "whitelist", "[DEPRECATED] will be ignored")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
|
@ -16,14 +16,14 @@ import (
|
||||||
// It searches for non-ASCII characters in each file's content and returns a list of paths to files containing non-ASCII characters.
|
// It searches for non-ASCII characters in each file's content and returns a list of paths to files containing non-ASCII characters.
|
||||||
func getNonAscii(root string) ([]string, error) {
|
func getNonAscii(root string) ([]string, error) {
|
||||||
var nonAscii []string
|
var nonAscii []string
|
||||||
noAttri := false
|
gitattrExist := true
|
||||||
var matcher gitattributes.Matcher
|
var matcher gitattributes.Matcher
|
||||||
_, err := os.Stat(".gitattributes")
|
_, err := os.Stat(".gitattributes")
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
noAttri = true
|
gitattrExist = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if !noAttri {
|
if gitattrExist {
|
||||||
fs := os.DirFS(".")
|
fs := os.DirFS(".")
|
||||||
f, err := fs.Open(".gitattributes")
|
f, err := fs.Open(".gitattributes")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -43,25 +43,19 @@ func getNonAscii(root string) ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
if info.Name() == ".git" || info.Name() == ".gitea" {
|
if info.Name() == ".git" {
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.Name() == "healthcheck" {
|
if gitattrExist {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if !noAttri {
|
|
||||||
relPath, err := filepath.Rel(root, path)
|
relPath, err := filepath.Rel(root, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
str := strings.Split(relPath, "/")
|
if _, ret := matcher.Match(strings.Split(relPath, "/"), nil); ret {
|
||||||
_, ret := matcher.Match(str, nil)
|
|
||||||
if ret {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user