repochecker/file-inspector: Handle ZIP archives
This commit is contained in:
parent
abb277210c
commit
60d790f8d3
3 changed files with 109 additions and 58 deletions
33
repochecker/file-inspector/zip.go
Normal file
33
repochecker/file-inspector/zip.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/sync"
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
func checkZip(path string, file *fic.EFile, exceptions *sync.CheckExceptions) (errs []error) {
|
||||
r, err := zip.OpenReader(path)
|
||||
if err != nil {
|
||||
log.Printf("Unable to open %q: %s", path, err.Error())
|
||||
return
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
if len(r.File) < 2 {
|
||||
if !exceptions.HasException(":one-file-tarball") {
|
||||
errs = append(errs, fmt.Errorf("don't make a ZIP archive for one file, use gzip instead"))
|
||||
}
|
||||
} else if len(r.File) < 5 && false {
|
||||
if !exceptions.HasException(":few-files-tarball") {
|
||||
errs = append(errs, fmt.Errorf("don't make a ZIP archive for so little files (:few-files-tarball)"))
|
||||
}
|
||||
} else {
|
||||
log.Printf("%d files found in %q", len(r.File), file.Name)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in a new issue