* ensure rename map is always sorted by path
This commit is contained in:
parent
c745ea01a3
commit
8aa33750a6
|
@ -22,7 +22,6 @@ import java.util.AbstractMap.SimpleImmutableEntry;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -142,7 +141,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
CLILogger.config(format("Rename episodes using [%s]", db.getName()));
|
||||
|
||||
// ignore sample files
|
||||
List<File> fileset = filter(files, not(getClutterFileFilter()));
|
||||
List<File> fileset = sortByUniquePath((filter(files, not(getClutterFileFilter()))));
|
||||
|
||||
List<File> mediaFiles = filter(fileset, VIDEO_FILES, SUBTITLE_FILES);
|
||||
if (mediaFiles.isEmpty()) {
|
||||
|
@ -224,7 +223,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
matches.addAll(derivateMatches);
|
||||
|
||||
// map old files to new paths by applying formatting and validating filenames
|
||||
Map<File, File> renameMap = new LinkedHashMap<File, File>();
|
||||
Map<File, File> renameMap = new TreeMap<File, File>(CASE_INSENSITIVE_PATH);
|
||||
|
||||
for (Match<File, ?> match : matches) {
|
||||
File file = match.getValue();
|
||||
|
@ -286,7 +285,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
CLILogger.config(format("Rename movies using [%s]", service.getName()));
|
||||
|
||||
// ignore sample files
|
||||
List<File> fileset = filter(files, not(getClutterFileFilter()));
|
||||
List<File> fileset = sortByUniquePath(filter(files, not(getClutterFileFilter())));
|
||||
|
||||
// handle movie files
|
||||
Set<File> movieFiles = new TreeSet<File>(filter(fileset, VIDEO_FILES));
|
||||
|
@ -467,7 +466,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
}
|
||||
|
||||
// map old files to new paths by applying formatting and validating filenames
|
||||
Map<File, File> renameMap = new LinkedHashMap<File, File>();
|
||||
Map<File, File> renameMap = new TreeMap<File, File>(CASE_INSENSITIVE_PATH);
|
||||
|
||||
for (Match<File, ?> match : matches) {
|
||||
File file = match.getValue();
|
||||
|
@ -484,7 +483,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
|
||||
public List<File> renameMusic(Collection<File> files, RenameAction renameAction, ConflictAction conflictAction, File outputDir, ExpressionFormat format, MusicIdentificationService service) throws Exception {
|
||||
CLILogger.config(format("Rename music using [%s]", service.getName()));
|
||||
List<File> audioFiles = filter(files, AUDIO_FILES);
|
||||
List<File> audioFiles = sortByUniquePath(filter(files, AUDIO_FILES));
|
||||
|
||||
// check audio files against acoustid
|
||||
List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
|
||||
|
@ -495,7 +494,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
}
|
||||
|
||||
// map old files to new paths by applying formatting and validating filenames
|
||||
Map<File, File> renameMap = new LinkedHashMap<File, File>();
|
||||
Map<File, File> renameMap = new TreeMap<File, File>(CASE_INSENSITIVE_PATH);
|
||||
|
||||
for (Match<File, ?> it : matches) {
|
||||
File file = it.getValue();
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.nio.file.AtomicMoveNotSupportedException;
|
|||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
@ -26,6 +27,7 @@ import java.util.Map;
|
|||
import java.util.Scanner;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -322,6 +324,14 @@ public final class FileUtilities {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static List<File> sortByUniquePath(Collection<File> files) {
|
||||
// sort by unique lower-case paths
|
||||
TreeSet<File> sortedSet = new TreeSet<File>(CASE_INSENSITIVE_PATH);
|
||||
sortedSet.addAll(files);
|
||||
|
||||
return new ArrayList<File>(sortedSet);
|
||||
}
|
||||
|
||||
public static List<File> filter(Iterable<File> files, FileFilter... filters) {
|
||||
List<File> accepted = new ArrayList<File>();
|
||||
|
||||
|
@ -665,6 +675,14 @@ public final class FileUtilities {
|
|||
}
|
||||
}
|
||||
|
||||
public static final Comparator<File> CASE_INSENSITIVE_PATH = new Comparator<File>() {
|
||||
|
||||
@Override
|
||||
public int compare(File o1, File o2) {
|
||||
return o1.getPath().compareToIgnoreCase(o2.getPath());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Dummy constructor to prevent instantiation.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue