sync: Fix a div by 0 when no exercice detected in theme

This commit is contained in:
nemunaire 2021-08-30 18:31:32 +02:00
parent 7e13cf28bd
commit 867e9bb345

View File

@ -5,8 +5,8 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"time"
"sync" "sync"
"time"
"srs.epita.fr/fic-server/libfic" "srs.epita.fr/fic-server/libfic"
"srs.epita.fr/fic-server/settings" "srs.epita.fr/fic-server/settings"
@ -48,12 +48,14 @@ func SpeedySyncDeep(i Importer) (errs map[string][]string) {
errs[theme.Name] = SyncExercices(i, theme) errs[theme.Name] = SyncExercices(i, theme)
if exercices, err := theme.GetExercices(); err == nil { if exercices, err := theme.GetExercices(); err == nil {
if len(exercices) == 0 {
continue
}
var exerciceStep uint8 = themeStep / uint8(len(exercices)) var exerciceStep uint8 = themeStep / uint8(len(exercices))
for eid, exercice := range exercices { for eid, exercice := range exercices {
log.Printf("Deep synchronization in progress: %d/255 - doing Theme %q, Exercice %q: %q\n", DeepSyncProgress, theme.Name, exercice.Title, exercice.Path) log.Printf("Speedy synchronization in progress: %d/255 - doing Theme %q, Exercice %q: %q\n", DeepSyncProgress, theme.Name, exercice.Title, exercice.Path)
DeepSyncProgress = 3 + uint8(tid)*themeStep + uint8(eid)*exerciceStep DeepSyncProgress = 3 + uint8(tid)*themeStep + uint8(eid)*exerciceStep
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFiles(i, exercice)...)
DeepSyncProgress += exerciceStep / 2 DeepSyncProgress += exerciceStep / 2
_, ferrs := SyncExerciceFlags(i, exercice) _, ferrs := SyncExerciceFlags(i, exercice)