When digest verification of a distfile fails, rename instead of unlinking it in case...
authorZac Medico <zmedico@gentoo.org>
Sat, 21 Jul 2007 00:24:06 +0000 (00:24 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 21 Jul 2007 00:24:06 +0000 (00:24 -0000)
svn path=/main/branches/2.1.2/; revision=7326

pym/portage.py

index cde08aa7e26a695765ebbc0ffb81ea01b0a13d8e..b7d9382374210a3b67d196a455eaaf3cd11fe110 100644 (file)
@@ -2654,9 +2654,15 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                                                                if reason[0] == "Insufficient data for checksum verification":
                                                                        return 0
                                                                if can_fetch and not restrict_fetch:
-                                                                       writemsg("Refetching...\n\n",
-                                                                               noiselevel=-1)
-                                                                       os.unlink(myfile_path)
+                                                                       from tempfile import mkstemp
+                                                                       fd, temp_filename = mkstemp("",
+                                                                               myfile + "._checksum_failure_.",
+                                                                               mysettings["DISTDIR"])
+                                                                       os.close(fd)
+                                                                       os.rename(myfile_path, temp_filename)
+                                                                       writemsg_stdout("Refetching... " + \
+                                                                               "File renamed to '%s'\n\n" % \
+                                                                               temp_filename, noiselevel=-1)
                                                        else:
                                                                eout = output.EOutput()
                                                                eout.quiet = \
@@ -2819,8 +2825,15 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                                                                                (reason[1], reason[2]), noiselevel=-1)
                                                                        if reason[0] == "Insufficient data for checksum verification":
                                                                                return 0
-                                                                       writemsg("Removing corrupt distfile...\n", noiselevel=-1)
-                                                                       os.unlink(mysettings["DISTDIR"]+"/"+myfile)
+                                                                       from tempfile import mkstemp
+                                                                       fd, temp_filename = mkstemp("",
+                                                                               myfile + "._checksum_failure_.",
+                                                                               mysettings["DISTDIR"])
+                                                                       os.close(fd)
+                                                                       os.rename(myfile_path, temp_filename)
+                                                                       writemsg_stdout("Refetching... " + \
+                                                                               "File renamed to '%s'\n\n" % \
+                                                                               temp_filename, noiselevel=-1)
                                                                        fetched=0
                                                                else:
                                                                        eout = output.EOutput()