skip already existing files

This commit is contained in:
2026-04-17 12:29:44 +02:00
parent 49c32e3f8f
commit cd7c3057b6

View File

@@ -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
}