2020-02-22 18:21:37 +04:00
|
|
|
// NNM-Club torrent filess mass downloader
|
|
|
|
// Created for Uploaders group
|
|
|
|
// Copyright (c) 2012-2020 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
package fetcherv1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Source: https://gist.github.com/var23rav/23ae5d0d4d830aff886c3c970b8f6c6b
|
|
|
|
|
|
|
|
/*
|
|
|
|
GoLang: os.Rename() give error "invalid cross-device link" for Docker container with Volumes.
|
|
|
|
moveFile(source, destination) will work moving file between folders
|
|
|
|
*/
|
|
|
|
|
|
|
|
func moveFile(sourcePath, destPath string) error {
|
|
|
|
inputFile, err := os.Open(sourcePath)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("couldn't open source file: %s", err)
|
|
|
|
}
|
2020-02-22 18:33:33 +04:00
|
|
|
|
2020-02-22 18:21:37 +04:00
|
|
|
outputFile, err := os.Create(destPath)
|
|
|
|
if err != nil {
|
|
|
|
inputFile.Close()
|
|
|
|
return fmt.Errorf("couldn't open destination file: %s", err)
|
|
|
|
}
|
|
|
|
defer outputFile.Close()
|
2020-02-22 18:33:33 +04:00
|
|
|
|
2020-02-22 18:21:37 +04:00
|
|
|
_, err = io.Copy(outputFile, inputFile)
|
|
|
|
inputFile.Close()
|
2020-02-22 18:33:33 +04:00
|
|
|
|
2020-02-22 18:21:37 +04:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("writing to output file failed: %s", err)
|
|
|
|
}
|
2020-02-22 18:33:33 +04:00
|
|
|
|
2020-02-22 18:21:37 +04:00
|
|
|
// The copy was successful, so now delete the original file
|
|
|
|
err = os.Remove(sourcePath)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed removing original file: %s", err)
|
|
|
|
}
|
2020-02-22 18:33:33 +04:00
|
|
|
|
2020-02-22 18:21:37 +04:00
|
|
|
return nil
|
|
|
|
}
|