mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-07-04 22:10:56 +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) {
|
public boolean rename(String filename, String newName) {
|
||||||
var fullPath = FileNames.join(fileSystemModel.getCurrentPath().get(), filename);
|
var fullPath = FileNames.join(fileSystemModel.getCurrentPath().get(), filename);
|
||||||
var newFullPath = FileNames.join(fileSystemModel.getCurrentPath().get(), newName);
|
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 {
|
try {
|
||||||
fileSystemModel.getFileSystem().move(fullPath, newFullPath);
|
fileSystemModel.getFileSystem().move(fullPath, newFullPath);
|
||||||
fileSystemModel.refresh();
|
fileSystemModel.refresh();
|
||||||
|
|
|
@ -204,6 +204,11 @@ public class FileSystemHelper {
|
||||||
|
|
||||||
var sourceFile = source.getPath();
|
var sourceFile = source.getPath();
|
||||||
var targetFile = FileNames.join(target.getPath(), FileNames.getFileName(sourceFile));
|
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) {
|
if (explicitCopy) {
|
||||||
target.getFileSystem().copy(sourceFile, targetFile);
|
target.getFileSystem().copy(sourceFile, targetFile);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class TerminalHelper {
|
||||||
public static void open(String title, String command) throws Exception {
|
public static void open(String title, String command) throws Exception {
|
||||||
var type = AppPrefs.get().terminalType().getValue();
|
var type = AppPrefs.get().terminalType().getValue();
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
throw new IllegalStateException(AppI18n.get("noTerminalSet"));
|
throw ErrorEvent.unreportable(new IllegalStateException(AppI18n.get("noTerminalSet")));
|
||||||
}
|
}
|
||||||
|
|
||||||
command = ScriptHelper.createLocalExecScript(command);
|
command = ScriptHelper.createLocalExecScript(command);
|
||||||
|
|
Loading…
Reference in a new issue