sync: Report custom errors

This commit is contained in:
nemunaire 2022-07-11 19:57:33 +02:00
commit c78545c18b
17 changed files with 510 additions and 137 deletions

View file

@ -0,0 +1,17 @@
package main
import (
"fmt"
"path"
"srs.epita.fr/fic-server/libfic"
)
func EPITACheckFile(file *fic.EFile) (errs []error) {
// Enforce file format
if path.Ext(file.Name) == "rar" || path.Ext(file.Name) == "7z" {
errs = append(errs, fmt.Errorf("this file use a forbidden archive type."))
}
return
}

View file

@ -0,0 +1,22 @@
package main
import (
"fmt"
"unicode"
"srs.epita.fr/fic-server/libfic"
)
func EPITACheckKeyFlag(flag *fic.FlagKey, raw string) (errs []error) {
if (flag.Label[0] == 'Q' || flag.Label[0] == 'q') && (flag.Label[1] == 'U' || flag.Label[1] == 'u') ||
(flag.Label[0] == 'W' || flag.Label[0] == 'w') && (flag.Label[1] == 'H' || flag.Label[1] == 'h') {
errs = append(errs, fmt.Errorf("Label should not begin with %s. This seem to be a question. Reword your label as a description of the expected flag, `:` are automatically appended.", flag.Label[0:2]))
flag.Label = flag.Label[1:]
}
if flag.Label[len(flag.Label)-1] != ')' && flag.Label[len(flag.Label)-1] != '©' && !unicode.IsLetter(rune(flag.Label[len(flag.Label)-1])) && !unicode.IsDigit(rune(flag.Label[len(flag.Label)-1])) {
errs = append(errs, fmt.Errorf("Label should not end with punct (%q). Reword your label as a description of the expected flag, `:` are automatically appended.", flag.Label[len(flag.Label)-1]))
}
return
}

10
repochecker/epita/main.go Normal file
View file

@ -0,0 +1,10 @@
package main
import (
"srs.epita.fr/fic-server/admin/sync"
)
func RegisterChecksHooks(h *sync.CheckHooks) {
h.RegisterFlagKeyHook(EPITACheckKeyFlag)
h.RegisterFileHook(EPITACheckFile)
}

View file

@ -3,6 +3,7 @@ package main
import (
"bufio"
"bytes"
"errors"
"flag"
"fmt"
"io/ioutil"
@ -22,6 +23,7 @@ var (
ignoreBinaryFileUnder = 1500000
skipFileChecks = false
skipBinaryFileCheck = false
logMissingResolution = false
)
func formatFileSize(size int) string {
@ -145,6 +147,7 @@ func main() {
cloudUsername := "fic"
cloudPassword := ""
localImporterDirectory := ""
checkplugins := sync.CheckPluginList{}
// Read paremeters from environment
if v, exists := os.LookupEnv("FICCLOUD_URL"); exists {
@ -167,9 +170,10 @@ func main() {
flag.BoolVar(&fic.OptionalDigest, "optionaldigest", fic.OptionalDigest, "Is the digest required when importing files?")
flag.BoolVar(&fic.StrongDigest, "strongdigest", fic.StrongDigest, "Are BLAKE2b digests required or is SHA-1 good enough?")
flag.BoolVar(&skipFileChecks, "skipfiledigests", skipFileChecks, "Don't perform DIGESTS checks on file to speed up the checks")
flag.BoolVar(&sync.LogMissingResolution, "skipresolution", sync.LogMissingResolution, "Don't fail if resolution.mp4 is absent")
flag.BoolVar(&logMissingResolution, "skipresolution", logMissingResolution, "Don't fail if resolution.mp4 is absent")
flag.BoolVar(&skipBinaryFileCheck, "skip-binary-file", skipBinaryFileCheck, "In Git-LFS check, don't warn files")
flag.IntVar(&ignoreBinaryFileUnder, "skip-binary-files-under", ignoreBinaryFileUnder, "In Git-LFS check, don't warn files under this size")
flag.Var(&checkplugins, "rules-plugins", "List of libraries containing others rules to checks")
flag.Parse()
// Do not display timestamp
@ -211,6 +215,15 @@ func main() {
log.Fatal("No importer nor path given!")
}
// Load rules plugins
for _, p := range checkplugins {
if err := sync.LoadChecksPlugin(p); err != nil {
log.Fatalf("Unable to load rule plugin %q: %s", p, err.Error())
} else {
log.Printf("Rules plugin %q successfully loaded", p)
}
}
// Variable that handles the exit status
hasError := false
@ -248,8 +261,17 @@ func main() {
for _, edir := range exercices {
for _, err := range checkExercice(theme, edir, &dmap) {
nberr += 1
log.Println(err.Error())
if logMissingResolution {
if e, ok := err.(*sync.ExerciceError); ok {
if errors.Is(e.GetError(), sync.ErrResolutionNotFound) {
continue
}
}
}
nberr += 1
}
log.Printf("================================== Exercice %q treated\n", edir)
}