diff --git a/admin/sync/exercice_files.go b/admin/sync/exercice_files.go index 90308cc8..06e1f3a6 100644 --- a/admin/sync/exercice_files.go +++ b/admin/sync/exercice_files.go @@ -1,6 +1,7 @@ package sync import ( + "compress/gzip" "encoding/hex" "fmt" "log" @@ -120,6 +121,25 @@ func CheckExerciceFiles(i Importer, exercice *fic.Exercice, exceptions *CheckExc if strings.HasSuffix(fname, ".gz") { if d, exists := digests[strings.TrimSuffix(fname, ".gz")]; exists { digest_shown = d + + // Check that gunzipped file digest is correct + if fd, closer, err := GetFile(i, path.Join(exercice.Path, "files", fname)); err != nil { + errs = append(errs, NewFileError(exercice, fname, fmt.Errorf("unable to read file: %w", err))) + continue + } else if gunzipfd, err := gzip.NewReader(fd); err != nil { + closer() + errs = append(errs, NewFileError(exercice, fname, fmt.Errorf("unable to gunzip file: %w", err))) + continue + } else { + defer gunzipfd.Close() + defer closer() + + hash160_inflate, hash512_inflate := fic.CreateHashBuffers(gunzipfd) + + if _, err := fic.CheckBufferHash(hash160_inflate, hash512_inflate, digest_shown); err != nil { + errs = append(errs, NewFileError(exercice, strings.TrimSuffix(fname, ".gz"), err)) + } + } } }