diff --git a/repochecker/file-inspector/zip.go b/repochecker/file-inspector/zip.go index 9d4d879d..a16135e3 100644 --- a/repochecker/file-inspector/zip.go +++ b/repochecker/file-inspector/zip.go @@ -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 }