sync: Better perform exception in exercices

This commit is contained in:
nemunaire 2023-07-09 19:05:58 +02:00
parent edbb867f62
commit dc83efa868
8 changed files with 45 additions and 34 deletions

View file

@ -93,7 +93,7 @@ func parseExerciceDirname(edir string) (eid int, ename string, err error) {
}
// BuildExercice creates an Exercice from a given importer.
func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*fic.Exercice, exceptions *CheckExceptions) (e *fic.Exercice, p ExerciceParams, eid int, edir string, errs []error) {
func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*fic.Exercice, exceptions_in *CheckExceptions) (e *fic.Exercice, p ExerciceParams, eid int, exceptions *CheckExceptions, edir string, errs []error) {
e = &fic.Exercice{}
e.Path = epath
@ -105,12 +105,12 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
// Ignore eid if we are certain this is an exercice directory, eid will be 0
if !i.Exists(path.Join(epath, "title.txt")) {
errs = append(errs, NewExerciceError(e, fmt.Errorf("unable to parse exercice directory: %w", err), theme))
return nil, p, eid, edir, errs
return nil, p, eid, exceptions_in, edir, errs
}
}
// Get exceptions
exceptions = LoadExerciceException(i, theme, e, exceptions)
exceptions = LoadExerciceException(i, theme, e, exceptions_in)
//log.Printf("Kept repochecker exceptions for this exercice: %v", exceptions)
e.Language = theme.Language
@ -350,12 +350,12 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
}
// SyncExercice imports new or updates existing given exercice.
func SyncExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*fic.Exercice, exceptions *CheckExceptions) (e *fic.Exercice, eid int, errs []error) {
func SyncExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*fic.Exercice, exceptions_in *CheckExceptions) (e *fic.Exercice, eid int, exceptions *CheckExceptions, errs []error) {
var err error
var p ExerciceParams
var berrors []error
e, p, eid, _, berrors = BuildExercice(i, theme, epath, dmap, exceptions)
e, p, eid, exceptions, _, berrors = BuildExercice(i, theme, epath, dmap, exceptions_in)
for _, e := range berrors {
errs = append(errs, e)
}
@ -403,7 +403,7 @@ func SyncExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*f
}
// SyncExercices imports new or updates existing exercices, in a given theme.
func SyncExercices(i Importer, theme *fic.Theme, exceptions *CheckExceptions) (errs []error) {
func SyncExercices(i Importer, theme *fic.Theme, exceptions *CheckExceptions) (exceptions_out map[int]*CheckExceptions, errs []error) {
if exercices, err := GetExercices(i, theme); err != nil {
errs = append(errs, err)
} else {
@ -412,10 +412,11 @@ func SyncExercices(i Importer, theme *fic.Theme, exceptions *CheckExceptions) (e
dmap, _ := buildDependancyMap(i, theme)
for _, edir := range exercices {
e, eid, cur_errs := SyncExercice(i, theme, path.Join(theme.Path, edir), &dmap, exceptions)
e, eid, ex_exceptions, cur_errs := SyncExercice(i, theme, path.Join(theme.Path, edir), &dmap, exceptions)
if e != nil {
emap[e.Title] = eid
dmap[int64(eid)] = e
exceptions_out[eid] = ex_exceptions
errs = append(errs, cur_errs...)
}
}
@ -453,7 +454,7 @@ func ApiListRemoteExercices(c *gin.Context) {
func ApiGetRemoteExercice(c *gin.Context) {
theme, exceptions, errs := BuildTheme(GlobalImporter, c.Params.ByName("thid"))
if theme != nil {
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil, exceptions)
exercice, _, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, c.Params.ByName("exid")), nil, exceptions)
if exercice != nil {
c.JSON(http.StatusOK, exercice)
return