Fix error with "invalid link" on torrent renaming
Now it uses custom trick instead of os.Rename().
This commit is contained in:
parent
9a2cab7364
commit
f30fb4dc67
domains/fetcher/v1
@ -1,6 +1,6 @@
|
|||||||
// NNM-Club torrent filess mass downloader
|
// NNM-Club torrent filess mass downloader
|
||||||
// Created for Uploaders group
|
// Created for Uploaders group
|
||||||
// Copyright (c) 2012-2019 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2012-2020 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package fetcherv1
|
package fetcherv1
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ func download(topic *forumTopic) {
|
|||||||
|
|
||||||
result := outputDirPath + "/" + lastModified + "-" + sanitize.BaseName(topic.Name) + ".torrent"
|
result := outputDirPath + "/" + lastModified + "-" + sanitize.BaseName(topic.Name) + ".torrent"
|
||||||
|
|
||||||
err = os.Rename(tempF, result)
|
err = moveFile(tempF, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dlog.Warn().Err(err).Str("название топика", topic.Name).Str("ссылка на топик", topic.Link).
|
dlog.Warn().Err(err).Str("название топика", topic.Name).Str("ссылка на топик", topic.Link).
|
||||||
Msg("Не удалось сохранить торрент-файл. Пропуск")
|
Msg("Не удалось сохранить торрент-файл. Пропуск")
|
||||||
|
42
domains/fetcher/v1/mover.go
Normal file
42
domains/fetcher/v1/mover.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user