Check for existence of target files for move operations

This commit is contained in:
crschnick 2023-08-26 15:40:47 +00:00
parent 3f6bba601d
commit 94db70bb2e
3 changed files with 21 additions and 1 deletions

View file

@ -110,6 +110,21 @@ public final class BrowserFileListModel {
public boolean rename(String filename, String newName) {
var fullPath = FileNames.join(fileSystemModel.getCurrentPath().get(), filename);
var newFullPath = FileNames.join(fileSystemModel.getCurrentPath().get(), newName);
boolean exists;
try {
exists = fileSystemModel.getFileSystem().fileExists(newFullPath) || fileSystemModel.getFileSystem().directoryExists(newFullPath);
} catch (Exception e) {
ErrorEvent.fromThrowable(e).handle();
return false;
}
if (exists) {
ErrorEvent.fromMessage("Target " + newFullPath + " does already exist").unreportable().handle();
fileSystemModel.refresh();
return false;
}
try {
fileSystemModel.getFileSystem().move(fullPath, newFullPath);
fileSystemModel.refresh();

View file

@ -204,6 +204,11 @@ public class FileSystemHelper {
var sourceFile = source.getPath();
var targetFile = FileNames.join(target.getPath(), FileNames.getFileName(sourceFile));
if (source.getKind() == FileKind.DIRECTORY && target.getFileSystem().directoryExists(targetFile)) {
throw ErrorEvent.unreportable(new IllegalArgumentException("Target directory " + targetFile + " does already exist"));
}
if (explicitCopy) {
target.getFileSystem().copy(sourceFile, targetFile);
} else {

View file

@ -17,7 +17,7 @@ public class TerminalHelper {
public static void open(String title, String command) throws Exception {
var type = AppPrefs.get().terminalType().getValue();
if (type == null) {
throw new IllegalStateException(AppI18n.get("noTerminalSet"));
throw ErrorEvent.unreportable(new IllegalStateException(AppI18n.get("noTerminalSet")));
}
command = ScriptHelper.createLocalExecScript(command);