mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-10 09:20:28 +00:00
Add path-based error constructor to FileSystemException
This doesn't change any functionality, but means we only construct "/{path}: {message}" strings in one location.
This commit is contained in:
parent
052e7a7ae5
commit
4566cb8273
@ -224,11 +224,11 @@ public class FileSystem {
|
|||||||
public synchronized void copy(String sourcePath, String destPath) throws FileSystemException {
|
public synchronized void copy(String sourcePath, String destPath) throws FileSystemException {
|
||||||
sourcePath = sanitizePath(sourcePath);
|
sourcePath = sanitizePath(sourcePath);
|
||||||
destPath = sanitizePath(destPath);
|
destPath = sanitizePath(destPath);
|
||||||
if (isReadOnly(destPath)) throw new FileSystemException("/" + destPath + ": " + ACCESS_DENIED);
|
if (isReadOnly(destPath)) throw new FileSystemException(destPath, ACCESS_DENIED);
|
||||||
if (!exists(sourcePath)) throw new FileSystemException("/" + sourcePath + ": " + NO_SUCH_FILE);
|
if (!exists(sourcePath)) throw new FileSystemException(sourcePath, NO_SUCH_FILE);
|
||||||
if (exists(destPath)) throw new FileSystemException("/" + destPath + ": " + FILE_EXISTS);
|
if (exists(destPath)) throw new FileSystemException(destPath, FILE_EXISTS);
|
||||||
if (contains(sourcePath, destPath)) {
|
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);
|
copyRecursive(sourcePath, getMount(sourcePath), destPath, getMount(destPath), 0);
|
||||||
}
|
}
|
||||||
@ -341,7 +341,7 @@ public class FileSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (match == null) {
|
if (match == null) {
|
||||||
throw new FileSystemException("/" + path + ": Invalid Path");
|
throw new FileSystemException(path, "Invalid Path");
|
||||||
}
|
}
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,12 @@ public class FileSystemException extends Exception {
|
|||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = -2500631644868104029L;
|
private static final long serialVersionUID = -2500631644868104029L;
|
||||||
|
|
||||||
FileSystemException(String s) {
|
FileSystemException(String message) {
|
||||||
super(s);
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileSystemException(String path, String message) {
|
||||||
|
this("/" + path + ": " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FileSystemException of(IOException e) {
|
public static FileSystemException of(IOException e) {
|
||||||
|
@ -129,7 +129,7 @@ class MountWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void makeDirectory(String path) throws FileSystemException {
|
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);
|
path = toLocal(path);
|
||||||
try {
|
try {
|
||||||
@ -140,7 +140,7 @@ class MountWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void delete(String path) throws FileSystemException {
|
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);
|
path = toLocal(path);
|
||||||
try {
|
try {
|
||||||
@ -151,7 +151,7 @@ class MountWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void rename(String source, String dest) throws FileSystemException {
|
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);
|
source = toLocal(source);
|
||||||
dest = toLocal(dest);
|
dest = toLocal(dest);
|
||||||
@ -168,7 +168,7 @@ class MountWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SeekableByteChannel openForWrite(String path, Set<OpenOption> options) throws FileSystemException {
|
public SeekableByteChannel openForWrite(String path, Set<OpenOption> options) throws FileSystemException {
|
||||||
if (writableMount == null) throw exceptionOf(path, ACCESS_DENIED);
|
if (writableMount == null) throw new FileSystemException(path, ACCESS_DENIED);
|
||||||
|
|
||||||
path = toLocal(path);
|
path = toLocal(path);
|
||||||
try {
|
try {
|
||||||
@ -206,10 +206,6 @@ class MountWrapper {
|
|||||||
|
|
||||||
private FileSystemException localExceptionOf(String path, String message) {
|
private FileSystemException localExceptionOf(String path, String message) {
|
||||||
if (!location.isEmpty()) path = path.isEmpty() ? location : location + "/" + path;
|
if (!location.isEmpty()) path = path.isEmpty() ? location : location + "/" + path;
|
||||||
return exceptionOf(path, message);
|
return new FileSystemException(path, message);
|
||||||
}
|
|
||||||
|
|
||||||
private static FileSystemException exceptionOf(String path, String message) {
|
|
||||||
return new FileSystemException("/" + path + ": " + message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user