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
1 changed files with 11 additions and 9 deletions

View File

@ -5,8 +5,8 @@ import (
"fmt"
"log"
"os"
"time"
"sync"
"time"
"srs.epita.fr/fic-server/libfic"
"srs.epita.fr/fic-server/settings"
@ -25,7 +25,7 @@ var DeepSyncProgress uint8
// SpeedySyncDeep performs a recursive synchronisation without importing files.
func SpeedySyncDeep(i Importer) (errs map[string][]string) {
oneDeepSync.Lock()
defer func(){
defer func() {
oneDeepSync.Unlock()
if DeepSyncProgress != 255 {
log.Printf("Speedy synchronization terminated at step %d/255", DeepSyncProgress)
@ -44,16 +44,18 @@ func SpeedySyncDeep(i Importer) (errs map[string][]string) {
var themeStep uint8 = uint8(250) / uint8(len(themes))
for tid, theme := range themes {
DeepSyncProgress = 3 + uint8(tid) * themeStep
DeepSyncProgress = 3 + uint8(tid)*themeStep
errs[theme.Name] = SyncExercices(i, theme)
if exercices, err := theme.GetExercices(); err == nil {
if len(exercices) == 0 {
continue
}
var exerciceStep uint8 = themeStep / uint8(len(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
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFiles(i, exercice)...)
DeepSyncProgress = 3 + uint8(tid)*themeStep + uint8(eid)*exerciceStep
DeepSyncProgress += exerciceStep / 2
_, ferrs := SyncExerciceFlags(i, exercice)
@ -74,7 +76,7 @@ func SpeedySyncDeep(i Importer) (errs map[string][]string) {
// SyncDeep performs a recursive synchronisation: from themes to challenge items.
func SyncDeep(i Importer) (errs map[string][]string) {
oneDeepSync.Lock()
defer func(){
defer func() {
oneDeepSync.Unlock()
if DeepSyncProgress != 255 {
log.Printf("Full synchronization terminated at step %d/255", DeepSyncProgress)
@ -167,7 +169,7 @@ func SyncThemeDeep(i Importer, theme fic.Theme, tid int, themeStep uint8) (errs
oneThemeDeepSync.Lock()
defer oneThemeDeepSync.Unlock()
DeepSyncProgress = 3 + uint8(tid) * themeStep
DeepSyncProgress = 3 + uint8(tid)*themeStep
errs = SyncExercices(i, theme)
if exercices, err := theme.GetExercices(); err == nil && len(exercices) > 0 {
@ -175,7 +177,7 @@ func SyncThemeDeep(i Importer, theme fic.Theme, tid int, themeStep uint8) (errs
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)
DeepSyncProgress = 3 + uint8(tid) * themeStep + uint8(eid) * exerciceStep
DeepSyncProgress = 3 + uint8(tid)*themeStep + uint8(eid)*exerciceStep
errs = append(errs, SyncExerciceFiles(i, exercice)...)
DeepSyncProgress += exerciceStep / 3