1
uploader_tools/internal/services/fetcher/mover.go
Vladimir Hodakov 32a2262e8c
Refactor and copyrights
Move domains to internal/services, remove unnecessary versioning for services.
Change copyright year.
2021-12-20 16:53:38 +04:00

48 lines
1.1 KiB
Go

// NNM-Club torrent filess mass downloader
// Created for Uploaders group
// Copyright (c) 2012-2020 Vladimir "fat0troll" Hodakov
package fetcher
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
}