This commit is contained in:
Reinhard Pointner 2016-07-31 13:36:07 +08:00
parent c7a80c7fec
commit c2add9937f
3 changed files with 34 additions and 30 deletions

View File

@ -1,11 +1,9 @@
package net.filebot;
import static java.util.Collections.*;
import static net.filebot.Logging.*;
import static net.filebot.util.FileUtilities.*;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CancellationException;
@ -66,27 +64,4 @@ public enum NativeRenameAction implements RenameAction {
}
}
public static void trash(File file) throws IOException {
// use system trash if possible
try {
if (Platform.isMac()) {
// use com.apple.eio package on OS X platform
if (com.apple.eio.FileManager.moveToTrash(file)) {
return;
}
} else if (com.sun.jna.platform.FileUtils.getInstance().hasTrash()) {
// use com.sun.jna.platform package on Windows and Linux
com.sun.jna.platform.FileUtils.getInstance().moveToTrash(new File[] { file });
return;
}
} catch (Exception e) {
debug.warning(e::toString);
}
// delete permanently if necessary
if (file.exists()) {
net.filebot.util.FileUtilities.delete(file);
}
}
}

View File

@ -1,11 +1,17 @@
package net.filebot;
import static net.filebot.Logging.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.attribute.BasicFileAttributes;
import com.apple.eio.FileManager;
import com.sun.jna.Platform;
import com.sun.jna.platform.FileUtils;
import net.filebot.util.FileUtilities;
public enum StandardRenameAction implements RenameAction {
@ -149,29 +155,52 @@ public enum StandardRenameAction implements RenameAction {
// reverse symlink
if (currentAttr.isSymbolicLink() && !originalAttr.isSymbolicLink()) {
NativeRenameAction.trash(current);
trash(current);
return original;
}
// reverse keeplink
if (!currentAttr.isSymbolicLink() && originalAttr.isSymbolicLink()) {
NativeRenameAction.trash(original);
trash(original);
return FileUtilities.moveRename(current, original);
}
// reverse copy / hardlink
if (currentAttr.isRegularFile() && originalAttr.isRegularFile()) {
NativeRenameAction.trash(current);
trash(current);
return original;
}
// reverse folder copy
if (currentAttr.isDirectory() && originalAttr.isDirectory()) {
NativeRenameAction.trash(original);
trash(original);
return FileUtilities.moveRename(current, original);
}
throw new IllegalArgumentException(String.format("Cannot revert file: %s => %s", current, original));
}
public static void trash(File file) throws IOException {
// use system trash if possible
try {
if (Platform.isMac()) {
// use com.apple.eio package on OS X platform
if (FileManager.moveToTrash(file)) {
return;
}
} else if (FileUtils.getInstance().hasTrash()) {
// use com.sun.jna.platform package on Windows and Linux
FileUtils.getInstance().moveToTrash(new File[] { file });
return;
}
} catch (Exception e) {
debug.warning(e::toString);
}
// delete permanently if necessary
if (file.exists()) {
FileUtilities.delete(file);
}
}
}

View File

@ -183,7 +183,7 @@ class RenameAction extends AbstractAction {
try {
for (File file : deleteFiles) {
if (file.exists()) {
NativeRenameAction.trash(file);
StandardRenameAction.trash(file);
}
}
} catch (Throwable e) {