mattetti / mpdgrabber

Experimental, unsupported tool to backup a mpd/dash stream
MIT License
1 stars 0 forks source link

os.Rename can't move files between file systems #1

Open Ingvix opened 1 month ago

Ingvix commented 1 month ago

On linux /tmp/ is usually on RAM. I'm trying to download a series with your francetv tool, but the files are downloaded to /tmp/ from which the subtitle is tried to move to the current folder, but it fails with error invalid cross-device link and so the remuxing fails as well, for the subtitle file isn't where the program expects it to be.

Ingvix commented 1 month ago

I stole and adapted this little function, and replaced the os.Rename functions with it, and it seems to work fine. I'm a bit too lazy to do all the honest forking and PM, so here you go. Use it if you will.

func Rename(src string, dst string) error {

    fin, err := os.Open(src)
    if err != nil {
        return fmt.Errorf("%w",err)
    }
    defer fin.Close()

    fout, err := os.Create(dst)
    if err != nil {
        return fmt.Errorf("%w",err)
    }
    defer fout.Close()

    _, err = io.Copy(fout, fin)

    if err != nil {
        return fmt.Errorf("%w",err)
    }

    err = os.Remove(src)
    if err != nil {
        Logger.Println("Couldn't delete temp file: " + src + "\n Please delete manually.\n")
    }
    return nil
}