2022-10-29 15:03:57 +00:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2022-10-31 15:38:32 +00:00
|
|
|
func (c *CheckExceptions) GetFileExceptions(paths ...string) *CheckExceptions {
|
2022-10-29 15:03:57 +00:00
|
|
|
if c == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := CheckExceptions{}
|
|
|
|
|
|
|
|
for k, v := range *c {
|
2022-10-31 15:38:32 +00:00
|
|
|
for _, path := range paths {
|
|
|
|
if strings.HasPrefix(k, "*:") || strings.HasPrefix(k, path) {
|
|
|
|
k = strings.TrimPrefix(k, path)
|
2022-10-29 15:03:57 +00:00
|
|
|
|
2022-10-31 15:38:32 +00:00
|
|
|
if strings.HasPrefix(k, "/") {
|
|
|
|
k = strings.TrimPrefix(k, "/")
|
|
|
|
}
|
2022-10-29 15:03:57 +00:00
|
|
|
|
2022-10-31 15:38:32 +00:00
|
|
|
ret[k] = v
|
|
|
|
break
|
|
|
|
}
|
2022-10-29 15:03:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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") {
|
2022-10-31 11:15:49 +00:00
|
|
|
(*exceptions)[strings.TrimSpace(line)] = fmt.Sprintf("repochecker-ack.txt:%d", n+1)
|
2022-10-29 15:03:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|