repochecker: Improve detection and messages

This commit is contained in:
nemunaire 2021-11-15 12:50:51 +01:00
parent 2d5b34ee01
commit 969c61017f
1 changed files with 17 additions and 4 deletions

View File

@ -19,11 +19,24 @@ import (
)
var (
ignoreBinaryFileUnder = 1000000
ignoreBinaryFileUnder = 1500000
skipFileChecks = false
strictBinaryFile = false
)
func formatFileSize(size int) string {
if size > 1000000000000 {
return fmt.Sprintf("%.1f TiB", float64(size)/float64(1<<40))
} else if size > 1000000000 {
return fmt.Sprintf("%.1f GiB", float64(size)/float64(1<<30))
} else if size > 1000000 {
return fmt.Sprintf("%.1f MiB", float64(size)/float64(1<<20))
} else if size > 1000 {
return fmt.Sprintf("%.1f KiB", float64(size)/float64(1<<10))
}
return fmt.Sprintf("%d B", size)
}
func searchBinaryInGit(edir string) (ret []string) {
// Check if git exists and if we are in a git repo
err := exec.Command("git", "-C", edir, "remote").Run()
@ -72,11 +85,11 @@ func searchBinaryInGit(edir string) (ret []string) {
}
continue
} else if fsize, err = strconv.Atoi(fields[3]); err == nil && fsize < ignoreBinaryFileUnder {
if _, ok := alreadySeen[fname]; !ok {
if _, ok := alreadySeen[fname]; !ok || !strictBinaryFile {
continue
}
} else if _, ok := alreadySeen[fname]; !ok && !strictBinaryFile {
alreadySeen[fname] = fmt.Sprintf("%s (commit %s) (size %d kB)", fname, commit[:7], fsize/1024)
alreadySeen[fname] = fmt.Sprintf("%s (commit %s) (size %s)", fname, commit[:7], formatFileSize(fsize))
continue
}
}
@ -84,7 +97,7 @@ func searchBinaryInGit(edir string) (ret []string) {
ret = append(ret, as)
alreadySeen[fname] = ""
}
ret = append(ret, fmt.Sprintf("%s (commit %s) (size %d kB)", fname, commit[:7], fsize/1024))
ret = append(ret, fmt.Sprintf("%s (commit %s) (size %s)", fname, commit[:7], formatFileSize(fsize)))
}
}
}