You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by ma...@apache.org on 2009/06/30 00:33:51 UTC

svn commit: r789476 - in /ant/ivy/core/trunk: CHANGES.txt src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java

Author: maartenc
Date: Mon Jun 29 22:33:50 2009
New Revision: 789476

URL: http://svn.apache.org/viewvc?rev=789476&view=rev
Log:
FIX: Ivy didn't fail when an outdated artifact in cache couldn't get deleted

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=789476&r1=789475&r2=789476&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Mon Jun 29 22:33:50 2009
@@ -96,6 +96,7 @@
 - IMPROVEMENT: Standalone runner should accept all the same parameters as ant tasks (IVY-1090)
 - IMPROVEMENT: Pre and post retrieve artifact events (IVY-1084)
 
+- FIX: Ivy didn't fail when an outdated artifact in cache couldn't get deleted
 - FIX: ivy:resolve ignores branch in "dynamic" resolve mode (IVY-1087) (thanks to Aleksey Zhukov)
 - FIX: [originalname] not expanded during retrieve when module descriptor contains extra attributes (IVY-1096)
 - FIX: The Ant output wasn't always prefixed by the name of the task

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java?rev=789476&r1=789475&r2=789476&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java Mon Jun 29 22:33:50 2009
@@ -49,6 +49,7 @@
 import org.apache.ivy.plugins.parser.ParserSettings;
 import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser;
 import org.apache.ivy.plugins.repository.ArtifactResourceResolver;
+import org.apache.ivy.plugins.repository.Resource;
 import org.apache.ivy.plugins.repository.ResourceDownloader;
 import org.apache.ivy.plugins.repository.ResourceHelper;
 import org.apache.ivy.plugins.resolver.DependencyResolver;
@@ -883,6 +884,7 @@
             Message.error("impossible to acquire lock for " + mrid);
             return null;
         }
+        BackupResourceDownloader backupDownloader = new BackupResourceDownloader(downloader);
         try {
             // now let's see if we can find it in cache and if it is up to date
             ResolvedModuleRevision rmr = doFindModuleInCache(mrid, options, null);
@@ -925,7 +927,7 @@
                     public ResolvedResource resolve(Artifact artifact) {
                         return mdRef;
                     }
-                }, downloader, 
+                }, backupDownloader,
                 new CacheDownloadOptions().setListener(options.getListener()).setForce(true));
             Message.verbose("\t" + report); 
 
@@ -970,7 +972,14 @@
                                 transformedArtifact, origin, false);
                             if (artFile.exists()) {
                                 Message.debug("deleting " + artFile);
-                                artFile.delete();
+                                if (!artFile.delete()) {
+                                    // Old artifacts couldn't get deleted!
+                                    // Restore the original ivy file so the next time we
+                                    // resolve the old artifacts are deleted again
+                                    backupDownloader.restore();
+                                    Message.error("Couldn't delete outdated artifact from cache: " + artFile);
+                                    return null;
+                                }
                             }
                             removeSavedArtifactOrigin(transformedArtifact);
                         }
@@ -999,6 +1008,7 @@
             }
         } finally {
             unlockMetadataArtifact(mrid);
+            backupDownloader.cleanUp();
         }
         
     }
@@ -1106,5 +1116,41 @@
         Message.debug("\t\tchangingPattern: " + getChangingPattern());
         Message.debug("\t\tchangingMatcher: " + getChangingMatcherName());
     }
+    
+    private class BackupResourceDownloader implements ResourceDownloader {
+        
+        private ResourceDownloader delegate;
+        private File backup;
+        private String originalPath;
+        
+        private BackupResourceDownloader(ResourceDownloader delegate) {
+            this.delegate = delegate;
+        }
+
+        public void download(Artifact artifact, Resource resource, File dest) throws IOException {
+            // keep a copy of the original file
+            if (dest.exists()) {
+                originalPath = dest.getAbsolutePath();
+                backup = new File(dest.getAbsolutePath() + ".backup");
+                FileUtil.copy(dest, backup, null, true);
+            }
+            delegate.download(artifact, resource, dest);
+        }
+        
+        public void restore() throws IOException {
+            if ((backup != null) && backup.exists()) {
+                File original = new File(originalPath);
+                FileUtil.copy(backup, original, null, true);
+                backup.delete();
+            }
+        }
+        
+        public void cleanUp() {
+            if ((backup != null) && backup.exists()) {
+                backup.delete();
+            }
+        }
+        
+    }
 
 }