jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r585472 - 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 Wed, 17 Oct 2007 12:59:27 GMT
Author: jukka
Date: Wed Oct 17 05:59:25 2007
New Revision: 585472

URL: http://svn.apache.org/viewvc?rev=585472&view=rev
Log:
JCR-1176: MemoryFileSystem is different from other FileSystems
    - Fixed incorrect behavior in MemoryFileSystem
    - Fixed incorrect tests in AbstractFileSystemTest

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=585472&r1=585471&r2=585472&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
Wed Oct 17 05:59:25 2007
@@ -92,11 +92,19 @@
     }
 
     public void deleteFolder(String folderPath) throws FileSystemException {
-        assertExistence(folderPath);
-        if (hasChildren(folderPath)) {
-            throw new FileSystemException(folderPath + " not empty");
+        assertIsFolder(folderPath);
+        Set allNames = entries.keySet();
+        Set selectedNames = new HashSet();
+        for (Iterator iter = allNames.iterator(); iter.hasNext();) {
+            String name = (String) iter.next();
+            if (name.startsWith(folderPath)) {
+                selectedNames.add(name);
+            }
+        }
+        for (Iterator iter = selectedNames.iterator(); iter.hasNext();) {
+            String name = (String) iter.next();
+            entries.remove(name);
         }
-        entries.remove(folderPath);
     }
 
     public boolean exists(String path) throws FileSystemException {
@@ -203,7 +211,7 @@
         for (Iterator iter = allNames.iterator(); iter.hasNext();) {
             String name = (String) iter.next();
             if (name.matches(folderPath + "/[^/]*") && !name.equals("/")) {
-                selectedNames.add(name);
+                selectedNames.add(name.substring(folderPath.length() + 1));
             }
         }
         return (String[]) selectedNames.toArray(new String[0]);
@@ -218,16 +226,17 @@
     }
 
     private String[] listInternal(String folderPath, boolean isFolder) {
-        String[] entryPaths = list(folderPath);
-        Set resultEntryPaths = new HashSet();
-        for (int i = 0; i < entryPaths.length; i++) {
-            String entryPath = entryPaths[i];
-            MemoryFileSystemEntry entry = getEntry(entryPath);
-            if (entry.isFolder() == isFolder) {
-                resultEntryPaths.add(entryPath);
+        String[] names = list(folderPath);
+        if (folderPath.equals("/")) {
+            folderPath = "";
+        }
+        Set result = new HashSet();
+        for (int i = 0; i < names.length; i++) {
+            if (getEntry(folderPath + "/" + names[i]).isFolder() == isFolder) {
+                result.add(names[i]);
             }
         }
-        return (String[]) resultEntryPaths.toArray(new String[0]);
+        return (String[]) result.toArray(new String[0]);
     }
 
     public void move(String srcPath, String destPath) {

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=585472&r1=585471&r2=585472&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
Wed Oct 17 05:59:25 2007
@@ -141,9 +141,10 @@
         fs.createFolder("/folder/subfolder");
         try {
             fs.deleteFolder("/folder");
-            fail("FileSystemException expected");
+            assertFalse(fs.exists("/folder"));
+            assertFalse(fs.exists("/folder/subfolder"));
         } catch (FileSystemException e) {
-            // ok
+            fail("unexpected FileSystemException");
         }
     }
 
@@ -161,18 +162,20 @@
         String[] entries = fs.list("/");
         assertEquals(2, entries.length);
         Arrays.sort(entries);
-        assertEquals(entries[0], "/file");
-        assertEquals(entries[1], "/folder");
+        System.out.println(entries[0]);
+        System.out.println(entries[1]);
+        assertEquals(entries[0], "file");
+        assertEquals(entries[1], "folder");
 
         entries = fs.list("/folder");
         assertEquals(2, entries.length);
         Arrays.sort(entries);
-        assertEquals(entries[0], "/folder/file");
-        assertEquals(entries[1], "/folder/subfolder");
+        assertEquals(entries[0], "file");
+        assertEquals(entries[1], "subfolder");
 
         entries = fs.listFiles("/folder");
         assertEquals(1, entries.length);
-        assertEquals(entries[0], "/folder/file");
+        assertEquals(entries[0], "file");
     }
 
 }



Mime
View raw message