2022-11-03 01:32:27 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"srs.epita.fr/fic-server/admin/sync"
|
|
|
|
"srs.epita.fr/fic-server/libfic"
|
|
|
|
)
|
|
|
|
|
|
|
|
func InspectFile(file *fic.EFile, exceptions *sync.CheckExceptions) (errs []error) {
|
|
|
|
i, ok := sync.GlobalImporter.(sync.LocalImporter)
|
|
|
|
if !ok {
|
|
|
|
log.Printf("Unable to load `file-inspector.so` as the current Importer is not a LocalImporter (%T).", sync.GlobalImporter)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
path := i.GetLocalPath(file.GetOrigin())
|
|
|
|
|
|
|
|
if filepath.Ext(file.Name) == ".tar" || strings.HasSuffix(file.Name, ".tar.gz") || strings.HasSuffix(file.Name, ".tar.bz2") {
|
2022-11-21 17:39:11 +00:00
|
|
|
// Check there is more than 1 file in tarball
|
|
|
|
errs = append(errs, checkTarball(path, file, exceptions)...)
|
|
|
|
} else if filepath.Ext(file.Name) == ".zip" {
|
|
|
|
// Check there is more than 1 file in zip
|
|
|
|
errs = append(errs, checkZip(path, file, exceptions)...)
|
2022-11-03 01:32:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|