Bug #305035 - Fix portdbapi.getfetchsizes() to account for
authorZac Medico <zmedico@gentoo.org>
Mon, 19 Jul 2010 05:07:42 +0000 (22:07 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 19 Jul 2010 05:07:42 +0000 (22:07 -0700)
PORTAGE_RO_DISTDIRS.

pym/portage/dbapi/porttree.py

index 238db8319d34771d5ef7fdb772f7552bb7fa0d0c..07a7b0c626a8aa7a187635640aca90b8cd536c4a 100644 (file)
@@ -785,10 +785,15 @@ class portdbapi(dbapi):
                        return {}
                filesdict={}
                myfiles = self.getFetchMap(mypkg, useflags=useflags)
+               ro_distdirs = [x for x in \
+                       shlex_split(self.settings.get("PORTAGE_RO_DISTDIRS", "")) \
+                       if os.path.isdir(x)]
                #XXX: maybe this should be improved: take partial downloads
                # into account? check checksums?
                for myfile in myfiles:
-                       if myfile not in checksums:
+                       try:
+                               fetch_size = int(checksums[myfile]["size"])
+                       except (KeyError, ValueError):
                                if debug:
                                        writemsg(_("[bad digest]: missing %(file)s for %(pkg)s\n") % {"file":myfile, "pkg":mypkg})
                                continue
@@ -800,9 +805,18 @@ class portdbapi(dbapi):
                                pass
                        if mystat is None:
                                existing_size = 0
+                               for x in ro_distdirs:
+                                       try:
+                                               mystat = os.stat(os.path.join(x, myfile))
+                                       except OSError:
+                                               pass
+                                       else:
+                                               if mystat.st_size == fetch_size:
+                                                       existing_size = fetch_size
+                                                       break
                        else:
                                existing_size = mystat.st_size
-                       remaining_size = int(checksums[myfile]["size"]) - existing_size
+                       remaining_size = fetch_size - existing_size
                        if remaining_size > 0:
                                # Assume the download is resumable.
                                filesdict[myfile] = remaining_size