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") | ||||
| 	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() | ||||
|  |  | |||
|  | @ -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 | ||||
| 			} | ||||
| 		} | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 zzjc1234
						zzjc1234