mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 13:42:59 +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:
		| @@ -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; | ||||
|     } | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
| @@ -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<OpenOption> 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); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonathan Coates
					Jonathan Coates