comparison mercurial/util.py @ 27391:4eeef1b2d689

merge with stable
author Matt Mackall <mpm@selenic.com>
date Wed, 16 Dec 2015 17:40:01 -0600
parents 45d996a566d7 c48ecc0b5bc9
children 6cd3044985c2
comparison
equal deleted inserted replaced
27390:8bc6ece9a2e1 27391:4eeef1b2d689
988 raise error.SignatureError 988 raise error.SignatureError
989 raise 989 raise
990 990
991 return check 991 return check
992 992
993 def copyfile(src, dest, hardlink=False): 993 def copyfile(src, dest, hardlink=False, copystat=False):
994 "copy a file, preserving mode and atime/mtime" 994 '''copy a file, preserving mode and optionally other stat info like
995 atime/mtime'''
995 if os.path.lexists(dest): 996 if os.path.lexists(dest):
996 unlink(dest) 997 unlink(dest)
997 # hardlinks are problematic on CIFS, quietly ignore this flag 998 # hardlinks are problematic on CIFS, quietly ignore this flag
998 # until we find a way to work around it cleanly (issue4546) 999 # until we find a way to work around it cleanly (issue4546)
999 if False and hardlink: 1000 if False and hardlink:
1002 return 1003 return
1003 except (IOError, OSError): 1004 except (IOError, OSError):
1004 pass # fall back to normal copy 1005 pass # fall back to normal copy
1005 if os.path.islink(src): 1006 if os.path.islink(src):
1006 os.symlink(os.readlink(src), dest) 1007 os.symlink(os.readlink(src), dest)
1008 # copytime is ignored for symlinks, but in general copytime isn't needed
1009 # for them anyway
1007 else: 1010 else:
1008 try: 1011 try:
1009 shutil.copyfile(src, dest) 1012 shutil.copyfile(src, dest)
1010 shutil.copymode(src, dest) 1013 if copystat:
1014 # copystat also copies mode
1015 shutil.copystat(src, dest)
1016 else:
1017 shutil.copymode(src, dest)
1011 except shutil.Error as inst: 1018 except shutil.Error as inst:
1012 raise Abort(str(inst)) 1019 raise Abort(str(inst))
1013 1020
1014 def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None): 1021 def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None):
1015 """Copy a directory tree using hardlinks if possible.""" 1022 """Copy a directory tree using hardlinks if possible."""