From: Andrew M. Kuchling Date: Fri, 1 Feb 2002 18:29:34 +0000 (+0000) Subject: [Bug #220993; may also fix bug #479469] Fix flakiness when old X-Git-Tag: v2.3c1~6745 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b388ec8b3a45ae45c0934ac04627e247762293c;p=python [Bug #220993; may also fix bug #479469] Fix flakiness when old installations are present, by always unlinking the destination file before copying to it. Without the unlink(), the copied file remains owned by its previous UID, causing the subsequent chmod() to fail. Bugfix candidate, though it may cause changes on platforms where file ownership behaves differently. --- diff --git a/Lib/distutils/file_util.py b/Lib/distutils/file_util.py index 526e4cf593..14772fb74a 100644 --- a/Lib/distutils/file_util.py +++ b/Lib/distutils/file_util.py @@ -36,6 +36,13 @@ def _copy_file_contents (src, dst, buffer_size=16*1024): raise DistutilsFileError, \ "could not open '%s': %s" % (src, errstr) + if os.path.exists(dst): + try: + os.unlink(dst) + except os.error, (errno, errstr): + raise DistutilsFileError, \ + "could not delete '%s': %s" % (dst, errstr) + try: fdst = open(dst, 'wb') except os.error, (errno, errstr):