comparison mercurial/util.py @ 23899:4e451d1359de

copyfile: allow optional hardlinking Some code paths use 'copyfiles' (full tree) for a single file to take advantage of the best-effort-hard-linking parameter. We add similar parameter and logic to 'copyfile' (single file) for this purpose. The single file version have the advantage to overwrite the destination file if it exists.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 05 Jan 2015 12:39:09 -0800
parents 6c44cef5baa2
children 3cbb5bf4035d
comparison
equal deleted inserted replaced
23898:b21c2e0ee8a3 23899:4e451d1359de
714 raise error.SignatureError 714 raise error.SignatureError
715 raise 715 raise
716 716
717 return check 717 return check
718 718
719 def copyfile(src, dest): 719 def copyfile(src, dest, hardlink=False):
720 "copy a file, preserving mode and atime/mtime" 720 "copy a file, preserving mode and atime/mtime"
721 if os.path.lexists(dest): 721 if os.path.lexists(dest):
722 unlink(dest) 722 unlink(dest)
723 if hardlink:
724 try:
725 oslink(src, dest)
726 return
727 except (IOError, OSError):
728 pass # fall back to normal copy
723 if os.path.islink(src): 729 if os.path.islink(src):
724 os.symlink(os.readlink(src), dest) 730 os.symlink(os.readlink(src), dest)
725 else: 731 else:
726 try: 732 try:
727 shutil.copyfile(src, dest) 733 shutil.copyfile(src, dest)