jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marti...@apache.org
Subject svn commit: r653417 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystem.java test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java
Date Mon, 05 May 2008 10:41:05 GMT
Author: martijnh
Date: Mon May  5 03:41:04 2008
New Revision: 653417

URL: http://svn.apache.org/viewvc?rev=653417&view=rev
Log:
JCR-1450 move method of the MemoryFileSystem may accept invalid destination path resulting
in invalid entries in FS

- Added unit test that shows the described behavior
- Added a fix to the MemoryFileSystem class

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystem.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystem.java?rev=653417&r1=653416&r2=653417&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystem.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/mem/MemoryFileSystem.java
Mon May  5 03:41:04 2008
@@ -246,6 +246,16 @@
             throw new FileSystemException("Destination exists: " + destPath);
         }
 
+        // Create destination folder if it does not yet exist
+        String[] path = destPath.split(SEPARATOR);
+        String folder = "";
+        for (int i = 1; i < path.length; i++) {
+            folder += SEPARATOR + path[i];
+            if (!exists(folder)) {
+                createFolder(folder);
+            }
+        }
+        
         Map moves = new HashMap();
         moves.put(srcPath, destPath);
         if (getEntry(srcPath).isFolder()) {

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java?rev=653417&r1=653416&r2=653417&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/fs/AbstractFileSystemTest.java
Mon May  5 03:41:04 2008
@@ -214,6 +214,61 @@
         assertEquals("subfolder", list[0]);
     }
 
+    public void testMoveFile_destFolderDoesNotExist() throws Exception {
+        // Create a folder with a file
+        fs.createFolder("/folder");
+        createFile("/folder/file", sampleBytes);
+
+        // Check that the destination folder and file do not exist
+        assertFalse(fs.exists("/folder2"));
+        assertFalse(fs.exists("/folder2/file"));
+
+        // Move the file into a non-existent directory
+        fs.move("/folder/file", "/folder2/file");
+
+        // Check that the file has been moved
+        assertFalse(fs.exists("/folder/file"));
+        assertFalse(fs.isFolder("/folder/file"));
+        assertFalse(fs.isFile("/folder/file"));
+        assertTrue(fs.exists("/folder2/file"));
+        assertFalse(fs.isFolder("/folder2/file"));
+        assertTrue(fs.isFile("/folder2/file"));
+
+        // Check that folder2 has been silently created
+        assertTrue(fs.exists("/folder2"));
+        assertTrue(fs.isFolder("/folder2"));
+        assertFalse(fs.isFile("/folder2"));
+    }
+    
+    public void testMoveFolder_destFolderDoesNotExist() throws Exception {
+        // Create a folder with a file
+        fs.createFolder("/folder");
+        createFile("/folder/file", sampleBytes);
+        // Check that the destination folder and file do not exist
+        assertFalse(fs.exists("/folder2"));
+        assertFalse(fs.exists("/folder2/folder3"));
+        assertFalse(fs.exists("/folder2/folder3/file"));
+
+        // Move the folder into a non-existent directory
+        fs.move("/folder", "/folder2/folder3");
+
+        // Assert
+        assertFalse(fs.exists("/folder"));
+        assertFalse(fs.exists("/folder/file"));
+        
+        assertTrue(fs.exists("/folder2"));
+        assertTrue(fs.isFolder("/folder2"));
+        assertFalse(fs.isFile("/folder2"));
+
+        assertTrue(fs.exists("/folder2/folder3"));
+        assertTrue(fs.isFolder("/folder2/folder3"));
+        assertFalse(fs.isFile("/folder2/folder3"));
+
+        assertTrue(fs.exists("/folder2/folder3/file"));
+        assertFalse(fs.isFolder("/folder2/folder3/file"));
+        assertTrue(fs.isFile("/folder2/folder3/file"));
+    }
+
     private void verifyStreamInput(
             InputStream inputStream, byte[] expectedBytes) throws IOException {
         byte[] resultBytes = new byte[3];



Mime
View raw message