Fix partial download size calculation for bug #116796.
authorZac Medico <zmedico@gentoo.org>
Fri, 21 Apr 2006 22:34:41 +0000 (22:34 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 21 Apr 2006 22:34:41 +0000 (22:34 -0000)
svn path=/main/trunk/; revision=3185

pym/portage.py

index 13495c3dc1a953560472d22bf2e6ad97c099d4ee..e0e178c81195851bd562808b2b691d18d9aa4ef2 100644 (file)
@@ -4802,12 +4802,27 @@ class portdbapi(dbapi):
                #XXX: maybe this should be improved: take partial downloads
                # into account? check checksums?
                for myfile in myfiles:
-                       if debug and myfile not in checksums.keys():
-                               print "[bad digest]: missing",myfile,"for",mypkg
-                       elif myfile in checksums.keys():
-                               distfile=settings["DISTDIR"]+"/"+myfile
-                               if not os.access(distfile, os.R_OK):
-                                       filesdict[myfile]=int(checksums[myfile]["size"])
+                       if myfile not in checksums:
+                               if debug:
+                                       writemsg("[bad digest]: missing %s for %s\n" % (myfile, mypkg))
+                               continue
+                       file_path = os.path.join(self.mysettings["DISTDIR"], myfile)
+                       mystat = None
+                       try:
+                               mystat = os.stat(file_path)
+                       except OSError, e:
+                               pass
+                       if mystat is None:
+                               existing_size = 0
+                       else:
+                               existing_size = mystat.st_size
+                       remaining_size = int(checksums[myfile]["size"]) - existing_size
+                       if remaining_size > 0:
+                               # Assume the download is resumable.
+                               filesdict[myfile] = remaining_size
+                       elif remaining_size < 0:
+                               # The existing file is too large and therefore corrupt.
+                               filesdict[myfile] = int(checksums[myfile]["size"])
                return filesdict
 
        def fetch_check(self, mypkg, useflags=None, mysettings=None, all=False):