Add --getbinpkg digest verification.
authorZac Medico <zmedico@gentoo.org>
Fri, 1 Jun 2007 17:33:23 +0000 (17:33 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 1 Jun 2007 17:33:23 +0000 (17:33 -0000)
svn path=/main/trunk/; revision=6709

pym/emerge/__init__.py
pym/portage/dbapi/bintree.py

index c653104a91123a157a654396c1f432f703c1e079..f14836dc18be87912b1e8019bda86b832e4ff742 100644 (file)
@@ -49,6 +49,7 @@ import portage.locks
 import portage.exception
 from portage.data import secpass
 from portage.util import normalize_path as normpath
+from portage.util import writemsg
 
 if not hasattr(__builtins__, "set"):
        from sets import Set as set
@@ -2939,6 +2940,8 @@ class MergeTask(object):
 
        def merge(self, mylist, favorites, mtimedb):
                failed_fetches = []
+               fetchonly = "--fetchonly" in self.myopts or \
+                       "--fetch-all-uri" in self.myopts
                mymergelist=[]
                ldpath_mtimes = mtimedb["ldpath"]
                xterm_titles = "notitles" not in self.settings.features
@@ -3239,9 +3242,29 @@ class MergeTask(object):
                                                        short_msg = "emerge: (%s of %s) %s Fetch" % \
                                                                (mergecount, len(mymergelist), pkg_key)
                                                        emergelog(xterm_titles, msg, short_msg=short_msg)
-                                                       if not self.trees[myroot]["bintree"].gettbz2(
-                                                               pkg_key):
-                                                               return 1
+                                                       try:
+                                                               self.trees[myroot]["bintree"].gettbz2(pkg_key)
+                                                       except portage.exception.FileNotFound:
+                                                               writemsg("!!! Fetching Binary failed " + \
+                                                                       "for '%s'\n" % pkg_key, noiselevel=-1)
+                                                               if not fetchonly:
+                                                                       return 1
+                                                               failed_fetches.append(pkg_key)
+                                                       except portage.exception.DigestException, e:
+                                                               writemsg("\n!!! Digest verification failed:\n",
+                                                                       noiselevel=-1)
+                                                               writemsg("!!! %s\n" % e.value[0],
+                                                                       noiselevel=-1)
+                                                               writemsg("!!! Reason: %s\n" % e.value[1],
+                                                                       noiselevel=-1)
+                                                               writemsg("!!! Got: %s\n" % e.value[2],
+                                                                       noiselevel=-1)
+                                                               writemsg("!!! Expected: %s\n" % e.value[3],
+                                                                       noiselevel=-1)
+                                                               os.unlink(mytbz2)
+                                                               if not fetchonly:
+                                                                       return 1
+                                                               failed_fetches.append(pkg_key)
                                        finally:
                                                if tbz2_lock:
                                                        portage.locks.unlockfile(tbz2_lock)
index c3a3aad1d09b939544cd2352ebe99362a84d152f..c6cc084c98a67769e94e9f44018870d2548e8797 100644 (file)
@@ -775,6 +775,7 @@ class binarytree(object):
                        else:
                                writemsg("Resuming download of this tbz2, but it is possible that it is corrupt.\n",
                                        noiselevel=-1)
+               tbz2_path = self.getname(pkgname)
                mydest = os.path.dirname(self.getname(pkgname))
                try:
                        os.makedirs(mydest, 0775)
@@ -797,9 +798,30 @@ class binarytree(object):
                else:
                        url = urljoin(base_url, tbz2name)
                        success = portage.getbinpkg.file_get(url, mydest, fcmd=fcmd)
-               if success:
-                       self.inject(pkgname)
-               return success
+               if success and "strict" in self.settings.features:
+                       metadata = self._remotepkgs[pkgname]
+                       digests = {}
+                       if "MD5" in metadata:
+                               digests["MD5"] = self._remotepkgs[pkgname]["MD5"]
+                       if "SIZE" in metadata:
+                               try:
+                                       digests["size"] = long(self._remotepkgs[pkgname]["SIZE"])
+                               except ValueError:
+                                       writemsg("!!! Malformed SIZE attribute in remote " + \
+                                       "metadata for '%s'\n" % pkgname)
+                       if digests:
+                               from portage.checksum import verify_all
+                               ok, reason = verify_all(tbz2_path, digests)
+                               if not ok:
+                                       raise portage.exception.DigestException(
+                                               tuple([tbz2_path]+list(reason)))
+               if not success:
+                       try:
+                               os.unlink(self.getname(pkgname))
+                       except OSError:
+                               pass
+                       raise portage.exception.FileNotFound(mydest)
+               self.inject(pkgname)
 
        def getslot(self, mycatpkg):
                "Get a slot for a catpkg; assume it exists."