From 20f5656a748208b633e987090316547c79a973d6 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 23 Nov 2022 16:59:00 +0100 Subject: [PATCH] repochecker/file-inspector: ZIP archive shouldn't contain Unix rootfs --- repochecker/file-inspector/zip.go | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) 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 }