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

Matt Mackall mpm at selenic.com
Sun Dec 5 10:29:00 CST 2010

On Sun, 2010-12-05 at 18:16 +1100, Brodie Rao wrote:
> # 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.

I don't think that analysis is quite right. Bookmarks are written with
atomictemp files, which don't use copyfile. The undo.bookmarks is
presumably created on commit to prepare for a rollback.

A more robust approach would probably include attempting to first delete
the target. This maximizes our odds of successfully writing to an
existing file. See localrepo:wwrite. If we can't delete files, we're
likely to soon have other problems writing and creating files.

Mathematics is the supreme nostalgia of our time.

More information about the Mercurial-devel mailing list