[PATCH 1 of 2 STABLE?] copyfile: add an optional parameter to copy atime/mtime
Siddharth Agarwal
sid at less-broken.com
Sat Dec 12 12:59:20 CST 2015
On 12/12/15 00:05, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0 at fb.com>
> # Date 1449907271 28800
> # Sat Dec 12 00:01:11 2015 -0800
> # Branch stable
> # Node ID 03e439fcc25a889ebc07f2143810dba2b7cf1fcc
> # Parent 59d5f619e69ec43f1957eddd85d4e1deddd64925
> # Available At http://42.netv6.net/sid0-wip/hg/
> # hg pull http://42.netv6.net/sid0-wip/hg/ -r 03e439fcc25a
> copyfile: add an optional parameter to copy atime/mtime
Going to send a V2 of this that copies over other stat data too.
>
> 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,
> 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 -- copytime is mostly useful for editors, most of
> which will dereference symlinks anyway.
>
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -16,7 +16,7 @@ hide platform-specific details from the
> import i18n
> _ = i18n._
> import error, osutil, encoding, parsers
> -import errno, shutil, sys, tempfile, traceback
> +import errno, shutil, stat, sys, tempfile, traceback
> import re as remod
> import os, time, datetime, calendar, textwrap, signal, collections
> import stat
> @@ -806,8 +806,8 @@ def checksignature(func):
>
> return check
>
> -def copyfile(src, dest, hardlink=False):
> - "copy a file, preserving mode and atime/mtime"
> +def copyfile(src, dest, hardlink=False, copytime=False):
> + "copy a file, preserving mode and optionally atime/mtime"
> if os.path.lexists(dest):
> unlink(dest)
> # hardlinks are problematic on CIFS, quietly ignore this flag
> @@ -820,10 +820,15 @@ def copyfile(src, dest, hardlink=False):
> 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 copytime and safehasattr(os, 'utime'):
> + st = os.lstat(src)
> + os.utime(dest, (st.st_atime, st.st_mtime))
> except shutil.Error as inst:
> raise Abort(str(inst))
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list