Mercurial > hg
changeset 27369:c48ecc0b5bc9 stable
copyfile: add an optional parameter to copy other stat data
Contrary to the comment, I didn't see any evidence that we were copying
atime/mtime at all. This adds a parameter to copyfile to optionally copy it and
other stat data, with the default being to not copy it.
Many systems don't support changing the timestamp of a symlink, but we don't
need that in general anyway -- copystat is mostly useful for editors, most of
which will dereference symlinks anyway.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Sat, 12 Dec 2015 11:00:04 -0800 |
parents | 59d5f619e69e |
children | d9e3ebe56970 |
files | mercurial/util.py |
diffstat | 1 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/util.py Mon Dec 07 21:42:50 2015 +0900 +++ b/mercurial/util.py Sat Dec 12 11:00:04 2015 -0800 @@ -806,8 +806,9 @@ return check -def copyfile(src, dest, hardlink=False): - "copy a file, preserving mode and atime/mtime" +def copyfile(src, dest, hardlink=False, copystat=False): + '''copy a file, preserving mode and optionally other stat info like + atime/mtime''' if os.path.lexists(dest): unlink(dest) # hardlinks are problematic on CIFS, quietly ignore this flag @@ -820,10 +821,16 @@ pass # fall back to normal copy if os.path.islink(src): os.symlink(os.readlink(src), dest) + # copytime is ignored for symlinks, but in general copytime isn't needed + # for them anyway else: try: shutil.copyfile(src, dest) - shutil.copymode(src, dest) + if copystat: + # copystat also copies mode + shutil.copystat(src, dest) + else: + shutil.copymode(src, dest) except shutil.Error as inst: raise Abort(str(inst))