package sync import ( "fmt" "path/filepath" "strings" "srs.epita.fr/fic-server/libfic" ) type CheckExceptions map[string]string func (c *CheckExceptions) GetExerciceExceptions(e *fic.Exercice) *CheckExceptions { return c.GetFileExceptions(filepath.Base(e.Path)) } func (c *CheckExceptions) GetFileExceptions(path string) *CheckExceptions { if c == nil { return nil } ret := CheckExceptions{} for k, v := range *c { if strings.HasPrefix(k, "*:") || strings.HasPrefix(k, path) { k = strings.TrimPrefix(k, path) if strings.HasPrefix(k, "/") { k = strings.TrimPrefix(k, "/") } ret[k] = v } } return &ret } func (c *CheckExceptions) HasException(ref string) bool { if c == nil { return false } for k, _ := range *c { if strings.HasSuffix(k, ref) { return true } } return false } func LoadException(i Importer, th *fic.Theme) (exceptions *CheckExceptions) { if fexcept, err := GetFileContent(i, filepath.Join(th.Path, "repochecker-ack.txt")); err == nil { exceptions = &CheckExceptions{} for n, line := range strings.Split(fexcept, "\n") { (*exceptions)[strings.TrimSpace(line)] = fmt.Sprintf("repochecker-ack.txt:%d", n+1) } } return }