Use pointer receiver more offen

This commit is contained in:
nemunaire 2021-11-22 15:35:07 +01:00
commit c7569b5e54
59 changed files with 688 additions and 672 deletions

View file

@ -13,7 +13,7 @@ import (
"srs.epita.fr/fic-server/libfic"
)
func BuildFilesListInto(i Importer, exercice fic.Exercice, into string) (files []string, digests map[string][]byte, errs []string) {
func BuildFilesListInto(i Importer, exercice *fic.Exercice, into string) (files []string, digests map[string][]byte, errs []string) {
// If no files directory, don't display error
if !i.exists(path.Join(exercice.Path, into)) {
return
@ -72,7 +72,7 @@ func BuildFilesListInto(i Importer, exercice fic.Exercice, into string) (files [
}
// CheckExerciceFilesPresence limits remote checks to presence, don't get it to check digest.
func CheckExerciceFilesPresence(i Importer, exercice fic.Exercice) (files []string, errs []string) {
func CheckExerciceFilesPresence(i Importer, exercice *fic.Exercice) (files []string, errs []string) {
flist, digests, berrs := BuildFilesListInto(i, exercice, "files")
errs = append(errs, berrs...)
@ -96,7 +96,7 @@ func CheckExerciceFilesPresence(i Importer, exercice fic.Exercice) (files []stri
}
// CheckExerciceFiles checks that remote files have the right digest.
func CheckExerciceFiles(i Importer, exercice fic.Exercice) (files []string, errs []string) {
func CheckExerciceFiles(i Importer, exercice *fic.Exercice) (files []string, errs []string) {
flist, digests, berrs := BuildFilesListInto(i, exercice, "files")
errs = append(errs, berrs...)
@ -117,7 +117,7 @@ func CheckExerciceFiles(i Importer, exercice fic.Exercice) (files []string, errs
// SyncExerciceFiles reads the content of files/ directory and import it as EFile for the given challenge.
// It takes care of DIGESTS.txt and ensure imported files match.
func SyncExerciceFiles(i Importer, exercice fic.Exercice) (errs []string) {
func SyncExerciceFiles(i Importer, exercice *fic.Exercice) (errs []string) {
if _, err := exercice.WipeFiles(); err != nil {
errs = append(errs, err.Error())
}
@ -138,7 +138,7 @@ func SyncExerciceFiles(i Importer, exercice fic.Exercice) (errs []string) {
}); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to import file %q: %s", path.Base(exercice.Path), fname, err))
continue
} else if f.(fic.EFile).Size == 0 {
} else if f.(*fic.EFile).Size == 0 {
errs = append(errs, fmt.Sprintf("%q: WARNING imported file %q is empty!", path.Base(exercice.Path), fname))
}
}
@ -149,15 +149,15 @@ func SyncExerciceFiles(i Importer, exercice fic.Exercice) (errs []string) {
func ApiGetRemoteExerciceFiles(ps httprouter.Params, _ []byte) (interface{}, error) {
theme, errs := BuildTheme(GlobalImporter, ps.ByName("thid"))
if theme != nil {
exercice, _, _, _, errs := BuildExercice(GlobalImporter, *theme, path.Join(theme.Path, ps.ByName("exid")), nil)
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, ps.ByName("exid")), nil)
if exercice != nil {
files, digests, errs := BuildFilesListInto(GlobalImporter, *exercice, "files")
files, digests, errs := BuildFilesListInto(GlobalImporter, exercice, "files")
if files != nil {
var ret []fic.EFile
var ret []*fic.EFile
for _, fname := range files {
fPath := path.Join(exercice.Path, "files", fname)
fSize, _ := getFileSize(GlobalImporter, fPath)
ret = append(ret, fic.EFile{
ret = append(ret, &fic.EFile{
Path: fPath,
Name: fname,
Checksum: digests[fname],