// 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) } outputFile, err := os.Create(destPath) if err != nil { inputFile.Close() return fmt.Errorf("couldn't open destination file: %s", err) } defer outputFile.Close() _, err = io.Copy(outputFile, inputFile) inputFile.Close() if err != nil { return fmt.Errorf("writing to output file failed: %s", err) } // 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) } return nil }