mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-06-30 20:10:57 +12:00
Check for existence of target files for move operations
This commit is contained in:
parent
3f6bba601d
commit
94db70bb2e
|
@ -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();
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue