diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 8a189d64f..811b7df1b 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -224,11 +224,11 @@ public class FileSystem { public synchronized void copy(String sourcePath, String destPath) throws FileSystemException { sourcePath = sanitizePath(sourcePath); destPath = sanitizePath(destPath); - if (isReadOnly(destPath)) throw new FileSystemException("/" + destPath + ": " + ACCESS_DENIED); - if (!exists(sourcePath)) throw new FileSystemException("/" + sourcePath + ": " + NO_SUCH_FILE); - if (exists(destPath)) throw new FileSystemException("/" + destPath + ": " + FILE_EXISTS); + if (isReadOnly(destPath)) throw new FileSystemException(destPath, ACCESS_DENIED); + if (!exists(sourcePath)) throw new FileSystemException(sourcePath, NO_SUCH_FILE); + if (exists(destPath)) throw new FileSystemException(destPath, FILE_EXISTS); if (contains(sourcePath, destPath)) { - throw new FileSystemException("/" + sourcePath + ": Can't copy a directory inside itself"); + throw new FileSystemException(sourcePath, "Can't copy a directory inside itself"); } copyRecursive(sourcePath, getMount(sourcePath), destPath, getMount(destPath), 0); } @@ -341,7 +341,7 @@ public class FileSystem { } } if (match == null) { - throw new FileSystemException("/" + path + ": Invalid Path"); + throw new FileSystemException(path, "Invalid Path"); } return match; } diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystemException.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystemException.java index a1dd0c416..38760f806 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystemException.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/FileSystemException.java @@ -13,8 +13,12 @@ public class FileSystemException extends Exception { @Serial private static final long serialVersionUID = -2500631644868104029L; - FileSystemException(String s) { - super(s); + FileSystemException(String message) { + super(message); + } + + FileSystemException(String path, String message) { + this("/" + path + ": " + message); } public static FileSystemException of(IOException e) { diff --git a/projects/core/src/main/java/dan200/computercraft/core/filesystem/MountWrapper.java b/projects/core/src/main/java/dan200/computercraft/core/filesystem/MountWrapper.java index 3a98d62b6..10d9243e2 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/filesystem/MountWrapper.java +++ b/projects/core/src/main/java/dan200/computercraft/core/filesystem/MountWrapper.java @@ -129,7 +129,7 @@ class MountWrapper { } public void makeDirectory(String path) throws FileSystemException { - if (writableMount == null) throw exceptionOf(path, ACCESS_DENIED); + if (writableMount == null) throw new FileSystemException(path, ACCESS_DENIED); path = toLocal(path); try { @@ -140,7 +140,7 @@ class MountWrapper { } public void delete(String path) throws FileSystemException { - if (writableMount == null) throw exceptionOf(path, ACCESS_DENIED); + if (writableMount == null) throw new FileSystemException(path, ACCESS_DENIED); path = toLocal(path); try { @@ -151,7 +151,7 @@ class MountWrapper { } public void rename(String source, String dest) throws FileSystemException { - if (writableMount == null) throw exceptionOf(source, ACCESS_DENIED); + if (writableMount == null) throw new FileSystemException(source, ACCESS_DENIED); source = toLocal(source); dest = toLocal(dest); @@ -168,7 +168,7 @@ class MountWrapper { } public SeekableByteChannel openForWrite(String path, Set options) throws FileSystemException { - if (writableMount == null) throw exceptionOf(path, ACCESS_DENIED); + if (writableMount == null) throw new FileSystemException(path, ACCESS_DENIED); path = toLocal(path); try { @@ -206,10 +206,6 @@ class MountWrapper { private FileSystemException localExceptionOf(String path, String message) { if (!location.isEmpty()) path = path.isEmpty() ? location : location + "/" + path; - return exceptionOf(path, message); - } - - private static FileSystemException exceptionOf(String path, String message) { - return new FileSystemException("/" + path + ": " + message); + return new FileSystemException(path, message); } }