34 lines
817 B
Go
34 lines
817 B
Go
|
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
|
||
|
}
|