admin: new argument --rapidimport to speed up the import but don't ensure consistency

This commit is contained in:
nemunaire 2016-12-30 20:23:19 +01:00 committed by nemunaire
parent 5c377f63de
commit fa7e0e25c4
2 changed files with 9 additions and 0 deletions

View File

@ -19,6 +19,7 @@ import (
var CloudDAVBase string var CloudDAVBase string
var CloudUsername string var CloudUsername string
var CloudPassword string var CloudPassword string
var RapidImport bool
type uploadedFile struct { type uploadedFile struct {
URI string URI string
@ -77,6 +78,13 @@ func createExerciceFile(exercice fic.Exercice, body []byte) (interface{}, error)
pathname := path.Join(fic.FilesDir, strings.ToLower(base32.StdEncoding.EncodeToString(hash[:])), path.Base(fromURI)) pathname := path.Join(fic.FilesDir, strings.ToLower(base32.StdEncoding.EncodeToString(hash[:])), path.Base(fromURI))
// Remove the file if it exists
if _, err := os.Stat(pathname); os.IsExist(err) && !RapidImport {
if err := os.Remove(pathname); err != nil {
return nil, err
}
}
if _, err := os.Stat(pathname); os.IsNotExist(err) { if _, err := os.Stat(pathname); os.IsNotExist(err) {
log.Println(logStr, pathname) log.Println(logStr, pathname)
if err := os.MkdirAll(path.Dir(pathname), 0777); err != nil { if err := os.MkdirAll(path.Dir(pathname), 0777); err != nil {

View File

@ -30,6 +30,7 @@ func main() {
"Base directory where found challenges files, cloud part") "Base directory where found challenges files, cloud part")
flag.StringVar(&api.CloudUsername, "clouduser", "fic", "Username used to sync") flag.StringVar(&api.CloudUsername, "clouduser", "fic", "Username used to sync")
flag.StringVar(&api.CloudPassword, "cloudpass", "", "Password used to sync") flag.StringVar(&api.CloudPassword, "cloudpass", "", "Password used to sync")
flag.BoolVar(&api.RapidImport, "rapidimport", false, "Don't try to reimport an existing file")
flag.Parse() flag.Parse()
log.SetPrefix("[admin] ") log.SetPrefix("[admin] ")