fix/nonascii_attributes #69

Merged
张泊明518370910136 merged 11 commits from fix/nonascii_attributes into master 2024-10-21 17:04:53 +08:00
2 changed files with 8 additions and 14 deletions
Showing only changes of commit 68e4c8e01e - Show all commits

View File

@ -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
zzjc123 marked this conversation as resolved Outdated

typo here

typo here

i mean it should be "remove localList" here, and "remove gitWhitelist“ down there

i mean it should be "remove localList" here, and "remove gitWhitelist“ down there
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()

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. // 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
zzjc123 marked this conversation as resolved Outdated

the naming is weird, we need to think what is !noAttri. Just sth like gitattributesExist.

the naming is weird, we need to think what is `!noAttri`. Just sth like `gitattributesExist`.
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" {
zzjc123 marked this conversation as resolved Outdated

Can we check the .gitea dir now?

Can we check the `.gitea` dir now?
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)
zzjc123 marked this conversation as resolved Outdated

and can this healthcheck skip be removed now?

and can this healthcheck skip be removed now?

no we can't for now.

no we can't for now.

what about now?

what about now?

what do you mean? for now we still need to copy the healthcheck bin into /w to run for test case. I don't now what's the better solution.

what do you mean? for now we still need to copy the healthcheck bin into /w to run for test case. I don't now what's the better solution.

oh sorry, I didn't see your commit. I will try it soon.

oh sorry, I didn't see your commit. I will try it soon.

it got fixed.

it got fixed.
if err != nil { if err != nil {
return err return err
} }
str := strings.Split(relPath, "/") if _, ret := matcher.Match(strings.Split(relPath, "/"), nil); ret {
zzjc123 marked this conversation as resolved Outdated

this line is too long now, should make it in two lines.

this line is too long now, should make it in two lines.
_, ret := matcher.Match(str, nil)
if ret {
return nil return nil
} }
} }