Author: cziegeler
Date: Wed Nov 28 08:39:07 2012
New Revision: 1414573

URL: http://svn.apache.org/viewvc?rev=1414573&view=rev
Log:
SLING-2683 :  File locations are absolute and don't work anymore if launchpad 
folder is moved 

Modified:
    
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
    
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java

Modified: 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java?rev=1414573&r1=1414572&r2=1414573&view=diff
==============================================================================
--- 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
 (original)
+++ 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
 Wed Nov 28 08:39:07 2012
@@ -184,7 +184,8 @@ public class PersistentResourceList {
         // first check untransformed resource if there are resources with the 
same url and digest
         for(final RegisteredResource rr : this.untransformedResources ) {
             if ( rr.getURL().equals(input.getURL()) && ( 
rr.getDigest().equals(input.getDigest())) ) {
-                // if we found the resource we can immediately return
+                // if we found the resource we can return after updating
+                ((RegisteredResourceImpl)rr).update(input);
                 return rr;
             }
         }
@@ -192,7 +193,8 @@ public class PersistentResourceList {
         for(final EntityResourceList group : this.data.values()) {
             for(final RegisteredResource rr : group.getResources()) {
                 if ( rr.getURL().equals(input.getURL()) && ( 
rr.getDigest().equals(input.getDigest()))) {
-                    // if we found the resource we can immediately return
+                    // if we found the resource we can return after updating
+                    ((RegisteredResourceImpl)rr).update(input);
                     return rr;
                 }
             }

Modified: 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java?rev=1414573&r1=1414572&r2=1414573&view=diff
==============================================================================
--- 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
 (original)
+++ 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
 Wed Nov 28 08:39:07 2012
@@ -147,6 +147,10 @@ public class RegisteredResourceImpl
                 this.digest = updatedDigest;
             }
         }
+        // update file location
+        if ( this.dataFile != null ) {
+            this.dataFile = 
FileDataStore.SHARED.getDataFile(this.dataFile.getName());
+        }
     }
 
     /**
@@ -363,6 +367,7 @@ public class RegisteredResourceImpl
     /**
      * @see java.lang.Object#equals(java.lang.Object)
      */
+    @Override
     public boolean equals(Object obj) {
         if ( obj == this ) {
             return true;
@@ -379,6 +384,7 @@ public class RegisteredResourceImpl
     /**
      * @see java.lang.Object#hashCode()
      */
+    @Override
     public int hashCode() {
         return this.getURL().hashCode();
     }
@@ -539,6 +545,32 @@ public class RegisteredResourceImpl
     }
 
     /**
+     * Update the resource uri - if provided.
+     */
+    public void update(final InternalResource rsrc) {
+        if ( rsrc.getResourceUri() != null ) {
+            FileDataStore.SHARED.removeFromDigestCache(this.url, this.digest);
+            this.removeDataFile();
+            this.dataUri = rsrc.getResourceUri();
+            if ( this.dictionary != null ) {
+                this.dictionary.put(InstallableResource.RESOURCE_URI_HINT, 
rsrc.getResourceUri());
+            }
+        } else if ( rsrc.getPrivateCopyOfFile() != null ) {
+            final boolean update = this.dataFile == null || 
!this.dataFile.getName().equals(rsrc.getPrivateCopyOfFile().getName());
+            if ( update ) {
+                if ( this.dictionary != null ) {
+                    
this.dictionary.remove(InstallableResource.RESOURCE_URI_HINT);
+                }
+                if ( this.dataFile != null ) {
+                    this.removeDataFile();
+                }
+                this.dataFile = rsrc.getPrivateCopyOfFile();
+                FileDataStore.SHARED.updateDigestCache(this.url, this.digest);
+            }
+        }
+    }
+
+    /**
      * Create a new resource with updated information
      */
     public TaskResource clone(TransformationResult transformationResult)


Reply via email to