[PATCH stable] util.copyfile: don't bail if shutil.copystat() raises OSError

Brodie Rao brodie at bitheap.org
Sun Dec 5 01:16:53 CST 2010


# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1291531599 -39600
# Branch stable
# Node ID a99156f9d3dcf0e32db794ad5f574bb8b0fc3c0e
# Parent  5e51254ad4d4c80669f462e310b2677f2b3c54a7
util.copyfile: don't bail if shutil.copystat() raises OSError

This allows operations using util.copyfile() to work even if
shutil.copystat() fails.

This is particularly important when working with repositories where
the current user is the not the owner but has write access to
it. Without this patch, doing something like updating a bookmark would
fail because the user doesn't have permission to call utime() on
.hg/undo.bookmarks.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -452,9 +452,12 @@ def copyfile(src, dest):
     else:
         try:
             shutil.copyfile(src, dest)
-            shutil.copystat(src, dest)
         except shutil.Error, inst:
             raise Abort(str(inst))
+        try:
+            shutil.copystat(src, dest)
+        except OSError:
+            pass
 
 def copyfiles(src, dst, hardlink=None):
     """Copy a directory tree using hardlinks if possible"""


More information about the Mercurial-devel mailing list