Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

Fix invalid cross-device link error #56

Merged
merged 1 commit into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common /* import "s32x.com/anirip/common" */

import (
"fmt"
"io"
"os"
"strings"
)
Expand All @@ -20,7 +21,29 @@ func Rename(src, dst string, i int) error {
if i > 0 {
return Rename(src, dst, i-1)
}
return err
return fmt.Errorf("renaming file: %w", err)
}
return nil
}

func Move(src, dst string) error {
source, err := os.Open(src)
if err != nil {
return fmt.Errorf("opening source file: %w", err)
}

// Defer executes in bottom-top order, so the file will close before it is removed
defer Delete(src)
defer source.Close()

dest, err := os.Create(dst)
if err != nil {
return fmt.Errorf("creating destination file: %w", err)
}

defer dest.Close()
if _, err := io.Copy(dest, source); err != nil {
return fmt.Errorf("copying source to destination file: %w", err)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ func download(showURL, user, pass, quality, origsubLang string) {
}

// Moves the episode to the appropriate season sub-directory
if err := common.Rename(tempDir+string(os.PathSeparator)+"episode.mkv",
if err := common.Move(tempDir+string(os.PathSeparator)+"episode.mkv",
show.GetTitle()+string(os.PathSeparator)+seasonMap[season.GetNumber()]+
string(os.PathSeparator)+episode.GetFilename()+".mkv", 10); err != nil {
string(os.PathSeparator)+episode.GetFilename()+".mkv"); err != nil {
log.Error(err)
}
log.Success("Downloading and merging completed successfully!")
Expand Down