repochecker/file-inspector: ZIP archive shouldn't contain Unix rootfs

This commit is contained in:
nemunaire 2022-11-23 16:59:00 +01:00
parent bd19d31577
commit 20f5656a74
1 changed files with 38 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
"strings"
"srs.epita.fr/fic-server/admin/sync"
"srs.epita.fr/fic-server/libfic"
@ -48,5 +49,42 @@ func checkZip(file *fic.EFile, exceptions *sync.CheckExceptions) (errs []error)
log.Printf("%d files found in %q", len(r.File), file.Name)
}
foundEtcDir := false
foundHomeDir := false
foundRootDir := false
foundVarDir := false
for _, file := range r.File {
if strings.HasPrefix(file.Name, "etc") {
foundEtcDir = true
}
if strings.HasPrefix(file.Name, "home") {
foundHomeDir = true
}
if strings.HasPrefix(file.Name, "root") {
foundRootDir = true
}
if strings.HasPrefix(file.Name, "var") {
foundVarDir = true
}
}
nbLinuxDirFound := 0
if foundEtcDir {
nbLinuxDirFound += 1
}
if foundHomeDir {
nbLinuxDirFound += 1
}
if foundRootDir {
nbLinuxDirFound += 1
}
if foundVarDir {
nbLinuxDirFound += 1
}
if nbLinuxDirFound > 2 && !exceptions.HasException(":not-a-linux-rootfs") {
errs = append(errs, fmt.Errorf("don't use a ZIP archive to store an Unix file system, prefer a tarball (:not-a-linux-rootfs)"))
}
return
}