diff --git a/src/main/java/org/filesys/smb/server/disk/JavaNIODeviceContext.java b/src/main/java/org/filesys/smb/server/disk/JavaNIODeviceContext.java index 7d4d049..e66247a 100644 --- a/src/main/java/org/filesys/smb/server/disk/JavaNIODeviceContext.java +++ b/src/main/java/org/filesys/smb/server/disk/JavaNIODeviceContext.java @@ -123,7 +123,7 @@ else if ( m_trashDir.isFile()) throw new DeviceContextException("Trashcan path is not a folder - " + m_trashDir.getAbsolutePath()); // Make sure the trashcan folder is on the same volume as the shared folder, so we can rename deleted files - if ( rootDir.getParent().equalsIgnoreCase( m_trashDir.getParent()) == false) { + if (!isTrashcanOnSameVolume(rootDir, m_trashDir)) { // File share and trash folders are not on the same volume throw new DeviceContextException("File share and trash folders must be on the same volume"); @@ -169,6 +169,24 @@ else if ( m_trashDir.isFile()) } } + /** + * Validate that the trashcan folder resides on the same volume as the shared + * folder. This is a requirement because we want to be able to move files into + * the trashcan by simply renaming them. + *

+ * The default implementation only uses a simple heuristic, override this method + * to provide a more advanced platform-specific check if required. + * + * @param rootDir The root directory of the shared folder + * @param trashCan The proposed trashcan directory + * @return True if the proposed trashcan directory is acceptable, false to + * signal an error + */ + protected boolean isTrashcanOnSameVolume(File rootDir, File trashCan) { + return trashCan.getAbsolutePath().startsWith(rootDir.getAbsolutePath()) + || rootDir.getParent().equalsIgnoreCase(m_trashDir.getParent()); + } + /** * Check if the trashcan folder is configured * diff --git a/src/main/java/org/filesys/smb/server/disk/JavaNIODiskDriver.java b/src/main/java/org/filesys/smb/server/disk/JavaNIODiskDriver.java index b25cb62..58604a3 100644 --- a/src/main/java/org/filesys/smb/server/disk/JavaNIODiskDriver.java +++ b/src/main/java/org/filesys/smb/server/disk/JavaNIODiskDriver.java @@ -1025,7 +1025,7 @@ public DeviceContext createContext(String shareName, ConfigElement args) throws DeviceContextException { // Parse the configuration and return the device context for this share - JavaNIODeviceContext ctx = new JavaNIODeviceContext( shareName, args); + JavaNIODeviceContext ctx = createJavaNIODeviceContext(shareName, args); // If the trashcan folder is configured then check if there are any trash files left over from a previous // server run @@ -1063,6 +1063,20 @@ public void run() { return ctx; } + /** + * Provide a new JavaNIODeviceContext for + * createContext Override this method to provide your own class. + * + * @param shareName + * @param args + * @return DeviceContext + * @throws DeviceContextException Error creating the device context + */ + protected JavaNIODeviceContext createJavaNIODeviceContext(String shareName, ConfigElement args) + throws DeviceContextException { + return new JavaNIODeviceContext(shareName, args); + } + /** * Connection opened to this disk device *