// Stop if interrupted
if(getState()==INTERRUPTED)
return false;
// Destination folder
AbstractFile destFolder = recurseParams==null?baseDestFolder:(AbstractFile)recurseParams;
// Is current file at the base folder level ?
boolean isFileInBaseFolder = files.indexOf(file)!=-1;
// Determine filename in destination
String originalName = file.getName();
String destFileName;
if(isFileInBaseFolder && newName!=null)
destFileName = newName;
else
destFileName = originalName;
// Create destination AbstractFile instance
AbstractFile destFile = createDestinationFile(destFolder, destFileName);
if (destFile == null)
return false;
// Do not follow symlink, simply delete it and return
if(file.isSymlink()) {
do { // Loop for retry
try {
file.delete();
return true;
}
catch(IOException e) {
LOGGER.debug("IOException caught", e);
int ret = showErrorDialog(errorDialogTitle, Translator.get("cannot_delete_file", file.getAbsolutePath()));
// Retry loops
if(ret==RETRY_ACTION)
continue;
// Cancel, skip or close dialog returns false
return false;
}
} while(true);
}
destFile = checkForCollision(file, destFolder, destFile, renameMode);
if (destFile == null)
return false;
// Let's try to rename the file using AbstractFile#renameTo() whenever possible, as it is more efficient
// than moving the file manually.
//
// Do not attempt to rename the file in the following cases:
// - destination has to be appended
// - file schemes do not match (at the time of writing, no filesystem supports mixed scheme renaming)
// - if the 'rename' operation is not supported
// Note: we want to avoid calling AbstractFile#renameTo when we know it will fail, as it performs some costly
// I/O bound checks and ends up throwing an exception which also comes at a cost.
if(!append && file.getURL().schemeEquals(destFile.getURL()) && file.isFileOperationSupported(FileOperation.RENAME)) {
try {
file.renameTo(destFile);
return true;
}
catch(IOException e) {
// Fail silently: renameTo might fail under normal conditions, for instance for local files which are
// not located on the same volume.
LOGGER.debug("Failed to rename "+file+" into "+destFile+" (not necessarily an error)", e);
}
}
// Rename couldn't be used or didn't succeed: move the file manually
// Move the directory and all its children recursively, by copying files to the destination and then deleting them.
if(file.isDirectory()) {
// create the destination folder if it doesn't exist
if(!(destFile.exists() && destFile.isDirectory())) {
do { // Loop for retry
try {
destFile.mkdir();
}
catch(IOException e) {
int ret = showErrorDialog(errorDialogTitle, Translator.get("cannot_create_folder", destFile.getAbsolutePath()));
// Retry loops
if(ret==RETRY_ACTION)
continue;
// Cancel, skip or close dialog returns false
return false;
}
break;
} while(true);
}
// move each file in this folder recursively
do { // Loop for retry
try {
AbstractFile subFiles[] = file.ls();
boolean isFolderEmpty = true;
for (AbstractFile subFile : subFiles) {
// Return now if the job was interrupted, so that we do not attempt to delete this folder
if (getState() == INTERRUPTED)
return false;