Do not report cached packages as being downloaded. (bnc #545295)
authorMichael Andres <ma@suse.de>
Thu, 12 Nov 2009 11:12:26 +0000 (12:12 +0100)
committerMichael Andres <ma@suse.de>
Thu, 12 Nov 2009 11:12:26 +0000 (12:12 +0100)
zypp/repo/PackageProvider.cc

index 551bfef..6b3f02a 100644 (file)
@@ -91,6 +91,31 @@ namespace zypp
       else
         url = * info.baseUrlsBegin();
 
+      { // check for cache hit:
+        OnMediaLocation loc( _package->location() );
+        PathInfo cachepath( info.packagesPath() / loc.filename() );
+
+        if ( cachepath.isFile() && ! loc.checksum().empty() ) // accept cache hit with matching checksum only!
+             // Tempting to do a quick check for matching .rpm-filesize before computing checksum,
+             // but real life shows that loc.downloadSize() and the .rpm-filesize frequently do not
+             // match, even if loc.checksum() and the .rpm-files checksum do. Blame the metadata generator(s).
+        {
+          CheckSum cachechecksum( loc.checksum().type(), filesystem::checksum( cachepath.path(), loc.checksum().type() ) );
+          USR << cachechecksum << endl;
+          if ( cachechecksum == loc.checksum() )
+          {
+            ManagedFile ret( cachepath.path() );
+            if ( ! info.keepPackages() )
+            {
+              ret.setDispose( filesystem::unlink );
+            }
+            MIL << "provided Package from cache " << _package << " at " << ret << endl;
+            return ret; // <-- cache hit
+          }
+        }
+      }
+
+      // HERE: cache misss, do download:
       MIL << "provide Package " << _package << endl;
       ScopedGuard guardReport( newReport() );
       ManagedFile ret;