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

Commit

Permalink
Merge pull request #56 from turtletowerz/master
Browse files Browse the repository at this point in the history
Fix invalid cross-device link error
  • Loading branch information
s32x authored Apr 24, 2020
2 parents 38020f9 + 6cd72e0 commit 8efa8cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
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

0 comments on commit 8efa8cf

Please sign in to comment.