* better handling of rename sets where the destination file already exists
This commit is contained in:
parent
331ac63201
commit
9065429152
|
@ -94,7 +94,9 @@ class RenameAction extends AbstractAction {
|
||||||
if (useExtendedFileAttributes()) {
|
if (useExtendedFileAttributes()) {
|
||||||
try {
|
try {
|
||||||
for (Match<Object, File> match : model.matches()) {
|
for (Match<Object, File> match : model.matches()) {
|
||||||
MediaDetection.storeMetaInfo(match.getCandidate(), match.getValue());
|
if (renameMap.containsKey(match.getCandidate()) && match.getValue() != null) {
|
||||||
|
MediaDetection.storeMetaInfo(match.getCandidate(), match.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Logger.getLogger(RenameAction.class.getName()).warning("Failed to write xattr: " + e.getMessage());
|
Logger.getLogger(RenameAction.class.getName()).warning("Failed to write xattr: " + e.getMessage());
|
||||||
|
@ -169,9 +171,6 @@ class RenameAction extends AbstractAction {
|
||||||
if (destinationSet.contains(destination))
|
if (destinationSet.contains(destination))
|
||||||
throw new IllegalArgumentException("Conflict detected: " + mapping.getValue().getPath());
|
throw new IllegalArgumentException("Conflict detected: " + mapping.getValue().getPath());
|
||||||
|
|
||||||
if (destination.exists())
|
|
||||||
throw new IllegalArgumentException("File already exists: " + mapping.getValue().getPath());
|
|
||||||
|
|
||||||
// use original mapping values
|
// use original mapping values
|
||||||
renameMap.put(mapping.getKey(), mapping.getValue());
|
renameMap.put(mapping.getKey(), mapping.getValue());
|
||||||
destinationSet.add(destination);
|
destinationSet.add(destination);
|
||||||
|
@ -304,8 +303,10 @@ class RenameAction extends AbstractAction {
|
||||||
firePropertyChange("currentFile", mapping.getKey(), mapping.getValue());
|
firePropertyChange("currentFile", mapping.getKey(), mapping.getValue());
|
||||||
|
|
||||||
// rename file, throw exception on failure
|
// rename file, throw exception on failure
|
||||||
if (!mapping.getKey().equals(mapping.getValue())) {
|
File source = mapping.getKey();
|
||||||
action.rename(mapping.getKey(), mapping.getValue());
|
File destination = resolveDestination(mapping.getKey(), mapping.getValue(), false);
|
||||||
|
if (!source.equals(destination)) {
|
||||||
|
action.rename(source, destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remember successfully renamed matches for history entry and possible revert
|
// remember successfully renamed matches for history entry and possible revert
|
||||||
|
@ -375,9 +376,19 @@ class RenameAction extends AbstractAction {
|
||||||
protected Map<File, File> doInBackground() throws Exception {
|
protected Map<File, File> doInBackground() throws Exception {
|
||||||
NativeRenameAction shell = (NativeRenameAction) action;
|
NativeRenameAction shell = (NativeRenameAction) action;
|
||||||
|
|
||||||
|
// prepare delta, ignore files already named as desired
|
||||||
|
Map<File, File> todo = new LinkedHashMap<File, File>();
|
||||||
|
for (Entry<File, File> mapping : renameMap.entrySet()) {
|
||||||
|
File source = mapping.getKey();
|
||||||
|
File destination = resolveDestination(mapping.getKey(), mapping.getValue(), false);
|
||||||
|
if (!source.equals(destination)) {
|
||||||
|
todo.put(source, destination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// call native shell move/copy
|
// call native shell move/copy
|
||||||
try {
|
try {
|
||||||
shell.rename(renameMap);
|
shell.rename(todo);
|
||||||
} catch (CancellationException e) {
|
} catch (CancellationException e) {
|
||||||
// set as cancelled and propagate the exception
|
// set as cancelled and propagate the exception
|
||||||
super.cancel(false);
|
super.cancel(false);
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class RenameModel extends MatchModel<Object, File> {
|
||||||
|
|
||||||
for (int i = 0; i < names.size(); i++) {
|
for (int i = 0; i < names.size(); i++) {
|
||||||
if (hasComplement(i)) {
|
if (hasComplement(i)) {
|
||||||
File originalFile = new File(files().get(i).getAbsolutePath());
|
File originalFile = files().get(i);
|
||||||
FormattedFuture formattedFuture = names.get(i);
|
FormattedFuture formattedFuture = names.get(i);
|
||||||
|
|
||||||
StringBuilder nameBuilder = new StringBuilder();
|
StringBuilder nameBuilder = new StringBuilder();
|
||||||
|
|
Loading…
Reference in New Issue