Improve handling of directories when permissions are missing

This commit is contained in:
crschnick 2024-05-17 18:44:49 +00:00
parent a1575f4042
commit 4a351f8598
2 changed files with 8 additions and 8 deletions

View file

@ -66,7 +66,7 @@ public class FileSystemHelper {
} }
} }
public static String resolveDirectoryPath(OpenFileSystemModel model, String path) throws Exception { public static String resolveDirectoryPath(OpenFileSystemModel model, String path, boolean allowRewrite) throws Exception {
if (path == null) { if (path == null) {
return null; return null;
} }
@ -90,14 +90,14 @@ public class FileSystemHelper {
throw new IllegalArgumentException(String.format("Directory %s is not absolute", resolved)); throw new IllegalArgumentException(String.format("Directory %s is not absolute", resolved));
} }
if (model.getFileSystem().fileExists(path)) { if (allowRewrite && model.getFileSystem().fileExists(path)) {
return FileNames.toDirectory(FileNames.getParent(path)); return FileNames.toDirectory(FileNames.getParent(path));
} }
return FileNames.toDirectory(resolved); return FileNames.toDirectory(resolved);
} }
public static void validateDirectoryPath(OpenFileSystemModel model, String path) throws Exception { public static void validateDirectoryPath(OpenFileSystemModel model, String path, boolean verifyExists) throws Exception {
if (path == null) { if (path == null) {
return; return;
} }
@ -111,7 +111,7 @@ public class FileSystemHelper {
return; return;
} }
if (!model.getFileSystem().directoryExists(path)) { if (verifyExists && !model.getFileSystem().directoryExists(path)) {
throw ErrorEvent.expected(new IllegalArgumentException(String.format("Directory %s does not exist", path))); throw ErrorEvent.expected(new IllegalArgumentException(String.format("Directory %s does not exist", path)));
} }

View file

@ -200,7 +200,7 @@ public final class OpenFileSystemModel extends BrowserSessionTab<FileSystemStore
cdSyncOrRetry(path, false).ifPresent(s -> cdSyncOrRetry(s, false)); cdSyncOrRetry(path, false).ifPresent(s -> cdSyncOrRetry(s, false));
} }
public Optional<String> cdSyncOrRetry(String path, boolean allowCommands) { public Optional<String> cdSyncOrRetry(String path, boolean customInput) {
if (Objects.equals(path, currentPath.get())) { if (Objects.equals(path, currentPath.get())) {
return Optional.empty(); return Optional.empty();
} }
@ -233,7 +233,7 @@ public final class OpenFileSystemModel extends BrowserSessionTab<FileSystemStore
} }
// Handle commands typed into navigation bar // Handle commands typed into navigation bar
if (allowCommands if (customInput
&& evaluatedPath != null && evaluatedPath != null
&& !evaluatedPath.isBlank() && !evaluatedPath.isBlank()
&& !FileNames.isAbsolute(evaluatedPath) && !FileNames.isAbsolute(evaluatedPath)
@ -263,7 +263,7 @@ public final class OpenFileSystemModel extends BrowserSessionTab<FileSystemStore
// Evaluate optional links // Evaluate optional links
String resolvedPath; String resolvedPath;
try { try {
resolvedPath = FileSystemHelper.resolveDirectoryPath(this, evaluatedPath); resolvedPath = FileSystemHelper.resolveDirectoryPath(this, evaluatedPath, customInput);
} catch (Exception ex) { } catch (Exception ex) {
ErrorEvent.fromThrowable(ex).handle(); ErrorEvent.fromThrowable(ex).handle();
return Optional.ofNullable(currentPath.get()); return Optional.ofNullable(currentPath.get());
@ -274,7 +274,7 @@ public final class OpenFileSystemModel extends BrowserSessionTab<FileSystemStore
} }
try { try {
FileSystemHelper.validateDirectoryPath(this, resolvedPath); FileSystemHelper.validateDirectoryPath(this, resolvedPath, customInput);
cdSyncWithoutCheck(path); cdSyncWithoutCheck(path);
} catch (Exception ex) { } catch (Exception ex) {
ErrorEvent.fromThrowable(ex).handle(); ErrorEvent.fromThrowable(ex).handle();