sync: Replace []error by go.uber.org/multierr
This commit is contained in:
parent
9f49a689fd
commit
b6966d47ce
25 changed files with 380 additions and 348 deletions
|
|
@ -4,17 +4,19 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/sync"
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
func InspectFile(file *fic.EFile, _ *fic.Exercice, exceptions *sync.CheckExceptions) (errs []error) {
|
||||
func InspectFile(file *fic.EFile, _ *fic.Exercice, exceptions *sync.CheckExceptions) (errs error) {
|
||||
if filepath.Ext(file.Name) == ".tar" || strings.HasSuffix(file.Name, ".tar.gz") || strings.HasSuffix(file.Name, ".tar.bz2") {
|
||||
// Check there is more than 1 file in tarball
|
||||
errs = append(errs, checkTarball(file, exceptions)...)
|
||||
errs = multierr.Append(errs, checkTarball(file, exceptions))
|
||||
} else if filepath.Ext(file.Name) == ".zip" {
|
||||
// Check there is more than 1 file in zip
|
||||
errs = append(errs, checkZip(file, exceptions)...)
|
||||
errs = multierr.Append(errs, checkZip(file, exceptions))
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
|||
|
|
@ -9,11 +9,13 @@ import (
|
|||
"log"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/sync"
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
func checkTarball(file *fic.EFile, exceptions *sync.CheckExceptions) (errs []error) {
|
||||
func checkTarball(file *fic.EFile, exceptions *sync.CheckExceptions) (errs error) {
|
||||
fd, closer, err := sync.GetFile(sync.GlobalImporter, file.GetOrigin())
|
||||
if err != nil {
|
||||
log.Printf("Unable to open %q: %s", file.GetOrigin(), err.Error())
|
||||
|
|
@ -56,11 +58,11 @@ func checkTarball(file *fic.EFile, exceptions *sync.CheckExceptions) (errs []err
|
|||
|
||||
if nbFile < 2 {
|
||||
if !exceptions.HasException(":one-file-tarball") {
|
||||
errs = append(errs, fmt.Errorf("don't make a tarball for one file"))
|
||||
errs = multierr.Append(errs, fmt.Errorf("don't make a tarball for one file"))
|
||||
}
|
||||
} else if nbFile < 5 && false {
|
||||
if !exceptions.HasException(":few-files-tarball") {
|
||||
errs = append(errs, fmt.Errorf("don't make a tarball for so little files (:few-files-tarball)"))
|
||||
errs = multierr.Append(errs, fmt.Errorf("don't make a tarball for so little files (:few-files-tarball)"))
|
||||
}
|
||||
} else {
|
||||
log.Printf("%d files found in %q", nbFile, file.Name)
|
||||
|
|
|
|||
|
|
@ -7,11 +7,13 @@ import (
|
|||
"log"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/sync"
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
func checkZip(file *fic.EFile, exceptions *sync.CheckExceptions) (errs []error) {
|
||||
func checkZip(file *fic.EFile, exceptions *sync.CheckExceptions) (errs error) {
|
||||
fd, closer, err := sync.GetFile(sync.GlobalImporter, file.GetOrigin())
|
||||
if err != nil {
|
||||
log.Printf("Unable to open %q: %s", file.GetOrigin(), err.Error())
|
||||
|
|
@ -39,11 +41,11 @@ func checkZip(file *fic.EFile, exceptions *sync.CheckExceptions) (errs []error)
|
|||
|
||||
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"))
|
||||
errs = multierr.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)"))
|
||||
errs = multierr.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)
|
||||
|
|
@ -83,7 +85,7 @@ func checkZip(file *fic.EFile, exceptions *sync.CheckExceptions) (errs []error)
|
|||
}
|
||||
|
||||
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)"))
|
||||
errs = multierr.Append(errs, fmt.Errorf("don't use a ZIP archive to store an Unix file system, prefer a tarball (:not-a-linux-rootfs)"))
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
|||
Reference in a new issue