skip already existing files
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user