admin: sync.ImportFile takes Importer as first arg

This commit is contained in:
nemunaire 2017-12-12 06:22:22 +01:00 committed by Pierre-Olivier Mercier
parent 9a9d5fcda4
commit 3d59042802
2 changed files with 9 additions and 5 deletions

View file

@ -70,9 +70,13 @@ func getFileContent(i Importer, URI string) (string, error) {
}
}
func ImportFile(URI string, next func(string, string) (interface{}, error)) (interface{}, error) {
func getDestinationFilePath(URI string) string {
hash := blake2b.Sum512([]byte(URI))
dest := path.Join(fic.FilesDir, strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:])), path.Base(URI))
return path.Join(fic.FilesDir, strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:])), path.Base(URI))
}
func ImportFile(i Importer, URI string, next func(string, string) (interface{}, error)) (interface{}, error) {
dest := getDestinationFilePath(URI)
// If the present file is still valide, don't erase it
if _, err := os.Stat(dest); !os.IsNotExist(err) {
@ -100,7 +104,7 @@ func ImportFile(URI string, next func(string, string) (interface{}, error)) (int
} else {
defer fdto.Close()
writer := bufio.NewWriter(fdto)
if err := getFile(GlobalImporter, URI, writer); err != nil {
if err := getFile(i, URI, writer); err != nil {
os.Remove(dest)
return nil, err
}