delete old anime episode when overwriting with higher priority file
This commit is contained in:
parent
f9050e1089
commit
965b5957e1
@ -8,6 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"git.milar.in/milarin/adverr"
|
||||
"git.milar.in/nyaanime/logic"
|
||||
"git.milar.in/nyaanime/model"
|
||||
"git.milar.in/nyaanime/parsers"
|
||||
@ -78,7 +79,7 @@ func HandleParsedFile(w io.Writer, parsedFile *model.ParsedFile) {
|
||||
}
|
||||
|
||||
if !animeEpNotExistLocally || newFilePrio.Priority > oldFilePrio.Priority {
|
||||
// TODO remove old file when overwriting existing episode (might have other file extension)
|
||||
DeleteOldAnimeEpisode(parsedFile.AnimeEpisode())
|
||||
if err := OrganizeAnimeEpisode(w, parsedFile); err != nil {
|
||||
fmt.Fprint(w, color.RedString("\terror: %s\n", err.Error()))
|
||||
}
|
||||
@ -139,3 +140,21 @@ func OrganizeAnimeEpisode(w io.Writer, parsedFile *model.ParsedFile) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteOldAnimeEpisode(animeEp model.AnimeEpisode) {
|
||||
animeEpPath := logic.GetAnimeEpFilepath(animeEp, "*")
|
||||
files, err := filepath.Glob(animeEpPath)
|
||||
if err != nil {
|
||||
panic(logic.ErrInvalidGlobSyntax.Wrap(err, animeEpPath))
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
if filepath.Ext(file) == ".lock" {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := os.Remove(file); err != nil {
|
||||
adverr.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user