jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: rev 55854 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: . fs state/obj state/xml
Date Thu, 28 Oct 2004 14:15:55 GMT
Author: stefan
Date: Thu Oct 28 07:15:55 2004
New Revision: 55854

Modified:
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BLOBFileValue.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/FileSystemResource.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
Log:
Jira issue JCR-14: {XML|Object}PersistenceManager.destroy(*) may fail 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BLOBFileValue.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BLOBFileValue.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BLOBFileValue.java	Thu
Oct 28 07:15:55 2004
@@ -170,15 +170,33 @@
 
     /**
      * Deletes the file backing this <code>BLOBFileValue</code>.
+     * Same as <code>{@link #delete(false)}</code>.
      */
     public void delete() {
+        delete(false);
+    }
+
+    /**
+     * Deletes the file backing this <code>BLOBFileValue</code>.
+     *
+     * @param pruneEmptyParentDirs if <code>true</code>, empty parent directories
will
+     *                             automatically be deleted
+     */
+    public void delete(boolean pruneEmptyParentDirs) {
         if (file != null) {
             // this instance is backed by a 'real' file
             file.delete();
+            if (pruneEmptyParentDirs) {
+                // prune empty parent directories
+                File parent = file.getParentFile();
+                while (parent != null && parent.delete()) {
+                    parent = parent.getParentFile();
+                }
+            }
         } else {
             // this instance is backed by a resource in the virtual file system
             try {
-                fsResource.delete();
+                fsResource.delete(pruneEmptyParentDirs);
             } catch (FileSystemException fse) {
                 // ignore
             }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/FileSystemResource.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/FileSystemResource.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/fs/FileSystemResource.java
Thu Oct 28 07:15:55 2004
@@ -97,10 +97,34 @@
     }
 
     /**
+     * Deletes this resource.
+     * Same as <code>{@link #delete(false)}</code>.
+     *
      * @see FileSystem#deleteFile
      */
     public void delete() throws FileSystemException {
         fs.deleteFile(path);
+    }
+
+    /**
+     * Deletes this resource.
+     *
+     * @param pruneEmptyParentDirs if <code>true</code>, empty parent folders
will
+     *                             automatically be deleted
+     * @see FileSystem#deleteFile
+     */
+    public void delete(boolean pruneEmptyParentDirs) throws FileSystemException {
+        fs.deleteFile(path);
+        if (pruneEmptyParentDirs) {
+            // prune empty parent folders
+            String parentDir = FileSystemPathUtil.getParentDir(path);
+            while (!parentDir.equals(FileSystem.SEPARATOR)
+                    && fs.exists(parentDir)
+                    && !fs.hasChildren(parentDir)) {
+                fs.deleteFolder(parentDir);
+                parentDir = FileSystemPathUtil.getParentDir(parentDir);
+            }
+        }
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
Thu Oct 28 07:15:55 2004
@@ -395,14 +395,8 @@
         if (!res.exists()) {
             return false;
         }
-        res.delete();
-        // prune empty folders
-        String parentDir = FileSystemPathUtil.getParentDir(blobId);
-        while (!parentDir.equals(FileSystem.SEPARATOR)
-                && !blobFS.hasChildren(parentDir)) {
-            blobFS.deleteFolder(parentDir);
-            parentDir = FileSystemPathUtil.getParentDir(parentDir);
-        }
+        // delete resource and prune empty parent folders
+        res.delete(true);
         return true;
     }
 
@@ -411,6 +405,10 @@
      * @see PersistenceManager#init
      */
     public void init(WorkspaceConfig wspConfig) throws Exception {
+        if (initialized) {
+            throw new IllegalStateException("already initialized");
+        }
+
         FileSystem wspFS = wspConfig.getFileSystem();
         itemStateFS = new BasedFileSystem(wspFS, "/data");
 
@@ -431,12 +429,13 @@
      */
     public synchronized void close() throws Exception {
         if (!initialized) {
-            return;
+            throw new IllegalStateException("not initialized");
         }
 
         try {
             // close blob store
             blobFS.close();
+            blobFS = null;
             /**
              * there's no need close the item state store because it
              * is based in the workspace's file system which is
@@ -456,15 +455,14 @@
             throw new IllegalStateException("not initialized");
         }
 
-        String uuid = state.getUUID();
-        String nodeFilePath = buildNodeFilePath(uuid);
+        String nodeFilePath = buildNodeFilePath(state.getUUID());
 
         try {
             if (!itemStateFS.isFile(nodeFilePath)) {
-                throw new NoSuchItemStateException(uuid);
+                throw new NoSuchItemStateException(state.getId().toString());
             }
         } catch (FileSystemException fse) {
-            String msg = "failed to read node state: " + uuid;
+            String msg = "failed to read node state: " + state.getId();
             log.error(msg, fse);
             throw new ItemStateException(msg, fse);
         }
@@ -476,14 +474,14 @@
                 deserialize(state, in);
                 return;
             } catch (Exception e) {
-                String msg = "failed to read node state: " + uuid;
+                String msg = "failed to read node state: " + state.getId();
                 log.error(msg, e);
                 throw new ItemStateException(msg, e);
             } finally {
                 in.close();
             }
         } catch (Exception e) {
-            String msg = "failed to read node state: " + uuid;
+            String msg = "failed to read node state: " + state.getId();
             log.error(msg, e);
             throw new ItemStateException(msg, e);
         }
@@ -498,16 +496,14 @@
             throw new IllegalStateException("not initialized");
         }
 
-        String parentUUID = state.getParentUUID();
-        QName propName = state.getName();
-        String propFilePath = buildPropFilePath(parentUUID, propName);
+        String propFilePath = buildPropFilePath(state.getParentUUID(), state.getName());
 
         try {
             if (!itemStateFS.isFile(propFilePath)) {
-                throw new NoSuchItemStateException(parentUUID + "/" + propName);
+                throw new NoSuchItemStateException(state.getId().toString());
             }
         } catch (FileSystemException fse) {
-            String msg = "failed to read property state: " + parentUUID + "/" + propName;
+            String msg = "failed to read property state: " + state.getId();
             log.error(msg, fse);
             throw new ItemStateException(msg, fse);
         }
@@ -522,7 +518,7 @@
                 in.close();
             }
         } catch (Exception e) {
-            String msg = "failed to read property state: " + parentUUID + "/" + propName;
+            String msg = "failed to read property state: " + state.getId();
             log.error(msg, e);
             throw new ItemStateException(msg, e);
         }
@@ -595,13 +591,9 @@
         String nodeFilePath = buildNodeFilePath(uuid);
         FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
         try {
-            nodeFile.delete();
-            // prune empty folders
-            String parentDir = FileSystemPathUtil.getParentDir(nodeFilePath);
-            while (!parentDir.equals(FileSystem.SEPARATOR)
-                    && !itemStateFS.hasChildren(parentDir)) {
-                itemStateFS.deleteFolder(parentDir);
-                parentDir = FileSystemPathUtil.getParentDir(parentDir);
+            if (nodeFile.exists()) {
+                // delete resource and prune empty parent folders
+                nodeFile.delete(true);
             }
         } catch (FileSystemException fse) {
             String msg = "failed to delete node state: " + uuid;
@@ -626,7 +618,8 @@
                 if (val != null) {
                     if (val.getType() == PropertyType.BINARY) {
                         BLOBFileValue blobVal = (BLOBFileValue) val.internalValue();
-                        blobVal.delete();
+                        // delete blob file and prune empty parent folders
+                        blobVal.delete(true);
                     }
                 }
             }
@@ -635,13 +628,9 @@
         String propFilePath = buildPropFilePath(state.getParentUUID(), state.getName());
         FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
         try {
-            propFile.delete();
-            // prune empty folders
-            String parentDir = FileSystemPathUtil.getParentDir(propFilePath);
-            while (!parentDir.equals(FileSystem.SEPARATOR)
-                    && !itemStateFS.hasChildren(parentDir)) {
-                itemStateFS.deleteFolder(parentDir);
-                parentDir = FileSystemPathUtil.getParentDir(parentDir);
+            if (propFile.exists()) {
+                // delete resource and prune empty parent folders
+                propFile.delete(true);
             }
         } catch (FileSystemException fse) {
             String msg = "failed to delete property state: " + state.getParentUUID() + "/"
+ state.getName();
@@ -659,15 +648,14 @@
             throw new IllegalStateException("not initialized");
         }
 
-        String uuid = refs.getTargetId().getUUID();
-        String refsFilePath = buildNodeReferencesFilePath(uuid);
+        String refsFilePath = buildNodeReferencesFilePath(refs.getTargetId().getUUID());
 
         try {
             if (!itemStateFS.isFile(refsFilePath)) {
-                throw new NoSuchItemStateException(uuid);
+                throw new NoSuchItemStateException(refs.getTargetId().toString());
             }
         } catch (FileSystemException fse) {
-            String msg = "failed to load references: " + uuid;
+            String msg = "failed to load references: " + refs.getTargetId();
             log.error(msg, fse);
             throw new ItemStateException(msg, fse);
         }
@@ -682,7 +670,7 @@
                 in.close();
             }
         } catch (Exception e) {
-            String msg = "failed to load references: " + uuid;
+            String msg = "failed to load references: " + refs.getTargetId();
             log.error(msg, e);
             throw new ItemStateException(msg, e);
         }
@@ -726,13 +714,9 @@
         String refsFilePath = buildNodeReferencesFilePath(uuid);
         FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
         try {
-            refsFile.delete();
-            // prune empty folders
-            String parentDir = FileSystemPathUtil.getParentDir(refsFilePath);
-            while (!parentDir.equals(FileSystem.SEPARATOR)
-                    && !itemStateFS.hasChildren(parentDir)) {
-                itemStateFS.deleteFolder(parentDir);
-                parentDir = FileSystemPathUtil.getParentDir(parentDir);
+            if (refsFile.exists()) {
+                // delete resource and prune empty parent folders
+                refsFile.delete(true);
             }
         } catch (FileSystemException fse) {
             String msg = "failed to delete references: " + uuid;

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
Thu Oct 28 07:15:55 2004
@@ -288,6 +288,10 @@
      * @see PersistenceManager#init
      */
     public void init(WorkspaceConfig wspConfig) throws Exception {
+        if (initialized) {
+            throw new IllegalStateException("already initialized");
+        }
+
         FileSystem wspFS = wspConfig.getFileSystem();
         itemStateStore = new BasedFileSystem(wspFS, "/data");
 
@@ -310,12 +314,13 @@
      */
     public synchronized void close() throws Exception {
         if (!initialized) {
-            return;
+            throw new IllegalStateException("not initialized");
         }
 
         try {
             // close blob store
             blobStore.close();
+            blobStore = null;
             /**
              * there's no need close the item state store because it
              * is based in the workspace's file system which is
@@ -697,13 +702,9 @@
         String nodeFilePath = buildNodeFilePath(uuid);
         FileSystemResource nodeFile = new FileSystemResource(itemStateStore, nodeFilePath);
         try {
-            nodeFile.delete();
-            // prune empty folders
-            String parentDir = FileSystemPathUtil.getParentDir(nodeFilePath);
-            while (!parentDir.equals(FileSystem.SEPARATOR)
-                    && !itemStateStore.hasChildren(parentDir)) {
-                itemStateStore.deleteFolder(parentDir);
-                parentDir = FileSystemPathUtil.getParentDir(parentDir);
+            if (nodeFile.exists()) {
+                // delete resource and prune empty parent folders
+                nodeFile.delete(true);
             }
         } catch (FileSystemException fse) {
             String msg = "failed to delete node state: " + uuid;
@@ -728,7 +729,8 @@
                 if (val != null) {
                     if (val.getType() == PropertyType.BINARY) {
                         BLOBFileValue blobVal = (BLOBFileValue) val.internalValue();
-                        blobVal.delete();
+                        // delete blob file and prune empty parent folders
+                        blobVal.delete(true);
                     }
                 }
             }
@@ -737,13 +739,9 @@
         String propFilePath = buildPropFilePath(state.getParentUUID(), state.getName());
         FileSystemResource propFile = new FileSystemResource(itemStateStore, propFilePath);
         try {
-            propFile.delete();
-            // prune empty folders
-            String parentDir = FileSystemPathUtil.getParentDir(propFilePath);
-            while (!parentDir.equals(FileSystem.SEPARATOR)
-                    && !itemStateStore.hasChildren(parentDir)) {
-                itemStateStore.deleteFolder(parentDir);
-                parentDir = FileSystemPathUtil.getParentDir(parentDir);
+            if (propFile.exists()) {
+                // delete resource and prune empty parent folders
+                propFile.delete(true);
             }
         } catch (FileSystemException fse) {
             String msg = "failed to delete property state: " + state.getParentUUID() + "/"
+ state.getName();
@@ -863,13 +861,9 @@
         String refsFilePath = buildNodeReferencesFilePath(uuid);
         FileSystemResource refsFile = new FileSystemResource(itemStateStore, refsFilePath);
         try {
-            refsFile.delete();
-            // prune empty folders
-            String parentDir = FileSystemPathUtil.getParentDir(refsFilePath);
-            while (!parentDir.equals(FileSystem.SEPARATOR)
-                    && !itemStateStore.hasChildren(parentDir)) {
-                itemStateStore.deleteFolder(parentDir);
-                parentDir = FileSystemPathUtil.getParentDir(parentDir);
+            if (refsFile.exists()) {
+                // delete resource and prune empty parent folders
+                refsFile.delete(true);
             }
         } catch (FileSystemException fse) {
             String msg = "failed to delete references: " + uuid;

Mime
View raw message