32 lines
956 B
Go
32 lines
956 B
Go
package sync
|
|
|
|
import (
|
|
"fmt"
|
|
"path"
|
|
|
|
"srs.epita.fr/fic-server/libfic"
|
|
)
|
|
|
|
func SyncExerciceHints(i Importer, exercice fic.Exercice) []string {
|
|
var errs []string
|
|
|
|
if _, err := exercice.WipeHints(); err != nil {
|
|
errs = append(errs, err.Error())
|
|
} else if ! i.exists(path.Join(exercice.Path, "hints")) {
|
|
return errs
|
|
} else if hints, err := i.listDir(path.Join(exercice.Path, "hints")); err != nil {
|
|
errs = append(errs, err.Error())
|
|
} else {
|
|
for n, hfile := range hints {
|
|
if hint_cnt, err := getFileContent(i, path.Join(exercice.Path, "hints", hfile)); err != nil {
|
|
errs = append(errs, fmt.Sprintf("%q: unable to read hint file %q: %s", path.Base(exercice.Path), hfile, err))
|
|
continue
|
|
} else if _, err := exercice.AddHint(fmt.Sprintf("Indice #%d", n + 1), hint_cnt, 1); err != nil {
|
|
errs = append(errs, fmt.Sprintf("%q: unable to add hint %q: %s", path.Base(exercice.Path), hfile, err))
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
return errs
|
|
}
|