You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2006/05/09 15:00:43 UTC

svn commit: r405419 - in /incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache: BundleArchive.java JarRevision.java

Author: rickhall
Date: Tue May  9 06:00:38 2006
New Revision: 405419

URL: http://svn.apache.org/viewcvs?rev=405419&view=rev
Log:
Modified the bundle archive implementation to reconstruct old bundle
revisions if they exist in the file system on startup. Such a situation
occurs if a bundle was updated and the framework uncleanly exited before
a refresh was performed. By recreating the existing revisions, the
framework will force a purge at startup to delete the old revision
directories and only keep the most recent revision (just as if a normal
refresh has occurred instead of an unclean exit in the previous session).

Modified:
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java?rev=405419&r1=405418&r2=405419&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java Tue May  9 06:00:38 2006
@@ -157,7 +157,40 @@
         m_logger = logger;
         m_archiveRootDir = archiveRootDir;
 
-        // Add a revision for the content.
+        // Add a revision for each one that already exists in the file
+        // system. The file system might contain more than one revision
+        // if the bundle was updated in a previous session, but the
+        // framework was not refreshed; this might happen if the framework
+        // did not exit cleanly. We must create the existing revisions so
+        // that they can be properly purged.
+        int revisionCount = 0;
+        while (true)
+        {
+            // Count the number of existing revision directories, which
+            // will be in a directory named like:
+            //     "${REVISION_DIRECTORY)${refresh-count}.${revision-count}"
+            File revisionRootDir = new File(m_archiveRootDir,
+                REVISION_DIRECTORY + getRefreshCount() + "." + revisionCount);
+            if (!BundleCache.getSecureAction().fileExists(revisionRootDir))
+            {
+                break;
+            }
+
+            // Increment the revision count.
+            revisionCount++;
+        }
+
+        // If there are multiple revisions in the file system, then create
+        // an array that is big enough to hold all revisions minus one; the
+        // call below to revise() will add the most recent revision. NOTE: We
+        // do not actually need to add a real revision object for the older
+        // revisions since they will be purged immediately on framework startup.
+        if (revisionCount > 1)
+        {
+            m_revisions = new BundleRevision[revisionCount - 1];
+        }
+
+        // Add the revision object for the most recent revision.
         revise(getCurrentLocation(), null);
     }
 
@@ -619,7 +652,14 @@
         File revisionDir = null;
         for (int i = 0; i < count - 1; i++)
         {
-            m_revisions[i].dispose();
+            // Dispose of the revision, but this might be null in certain
+            // circumstances, such as if this bundle archive was created
+            // for an existing bundle that was updated, but not refreshed
+            // due to a system crash; see the constructor code for details.
+            if (m_revisions[i] != null)
+            {
+                m_revisions[i].dispose();
+            }
             revisionDir = new File(m_archiveRootDir, REVISION_DIRECTORY + refreshCount + "." + i);
             if (BundleCache.getSecureAction().fileExists(revisionDir))
             {
@@ -797,7 +837,7 @@
     private BundleRevision createRevisionFromLocation(String location, InputStream is)
         throws Exception
     {
-        // The revision directory is name using the refresh count and
+        // The revision directory is named using the refresh count and
         // the revision count. The revision count is obvious, but the
         // refresh count is less obvious. This is necessary due to how
         // native libraries are handled in Java; needless to say, every

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java?rev=405419&r1=405418&r2=405419&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/cache/JarRevision.java Tue May  9 06:00:38 2006
@@ -259,7 +259,7 @@
                 return;
             }
 
-            // Create revision directory, if it does not exist.
+            // Create revision directory.
             if (!BundleCache.getSecureAction().mkdir(getRevisionRootDir()))
             {
                 getLogger().log(
@@ -297,7 +297,6 @@
                 BundleCache.copyStreamToFile(is, m_bundleFile);
             }
 
-            // This will always be revision zero.
             preprocessBundleJar();
         }
         finally