From cd7c3057b6f62175aae4673974718601160d6859 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Fri, 17 Apr 2026 12:29:44 +0200 Subject: [PATCH] skip already existing files --- internal/sorter.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/sorter.go b/internal/sorter.go index 3cdebe3..db89e6c 100644 --- a/internal/sorter.go +++ b/internal/sorter.go @@ -1,6 +1,7 @@ package ripsort import ( + "errors" "fmt" "io" "log/slog" @@ -30,8 +31,17 @@ func sortSong(src, dst string, updateMeta bool) error { dstPath := pathForFile(src, *m) finalPath := filepath.Join(dst, dstPath) - if updateMeta { + exists, err := fileExists(finalPath) + if err != nil { + return err + } + if exists { + slog.Info("File already exists", "file", src, "dst", dst) + return nil + } + + if updateMeta { slog.Info("Copying song with updated metadata", "file", src, "dst", dstPath) err = copyFileUpdateMetadata(src, finalPath, *m) if err != nil { @@ -191,3 +201,17 @@ func checkForExtraFiles(originalPath string) []string { return extraFiles } + +func fileExists(file string) (bool, error) { + _, err := os.Stat(file) + + if errors.Is(err, os.ErrNotExist) { + return false, nil + } + + if err != nil { + return false, err + } + + return true, nil +}