diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserFileListModel.java b/app/src/main/java/io/xpipe/app/browser/BrowserFileListModel.java index a6a6e393..7781f627 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserFileListModel.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserFileListModel.java @@ -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(); diff --git a/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java b/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java index 487ebb59..2432bef7 100644 --- a/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java +++ b/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java @@ -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 { diff --git a/app/src/main/java/io/xpipe/app/util/TerminalHelper.java b/app/src/main/java/io/xpipe/app/util/TerminalHelper.java index cf13ab8f..58277cd3 100644 --- a/app/src/main/java/io/xpipe/app/util/TerminalHelper.java +++ b/app/src/main/java/io/xpipe/app/util/TerminalHelper.java @@ -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);