fix(healthcheck/nonasciifile): comment, code style and check range
Some checks failed
build / build (push) Failing after 1m18s
build / trigger-build-image (push) Has been skipped
build / build (pull_request) Failing after 1m17s
build / trigger-build-image (pull_request) Has been skipped

This commit is contained in:
zzjc1234 2024-10-21 16:21:12 +08:00
parent 373d31cb5c
commit 68e4c8e01e
2 changed files with 8 additions and 14 deletions

View File

@ -43,12 +43,12 @@ func main() {
showVersion := flag.Bool("version", false, "print current version")
rootDir := flag.String("root", ".", "root dir for forbidden files check")
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")
checkFileNameList := flag.String("checkFileNameList", "", "comma-separated list of files to check")
checkFileSumList := flag.String("checkFileSumList", "", "comma-separated list of expected checksums")
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
parseMultiValueFlag(&gitWhitelist, "whitelist", "[DEPRECATED] will be ignored")
flag.Parse()

View File

@ -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.
func getNonAscii(root string) ([]string, error) {
var nonAscii []string
noAttri := false
gitattrExist := true
var matcher gitattributes.Matcher
_, err := os.Stat(".gitattributes")
if os.IsNotExist(err) {
noAttri = true
gitattrExist = false
}
if !noAttri {
if gitattrExist {
fs := os.DirFS(".")
f, err := fs.Open(".gitattributes")
if err != nil {
@ -43,25 +43,19 @@ func getNonAscii(root string) ([]string, error) {
}
if info.IsDir() {
if info.Name() == ".git" || info.Name() == ".gitea" {
if info.Name() == ".git" {
return filepath.SkipDir
} else {
return nil
}
}
if info.Name() == "healthcheck" {
return nil
}
if !noAttri {
if gitattrExist {
relPath, err := filepath.Rel(root, path)
if err != nil {
return err
}
str := strings.Split(relPath, "/")
_, ret := matcher.Match(str, nil)
if ret {
if _, ret := matcher.Match(strings.Split(relPath, "/"), nil); ret {
return nil
}
}