##// END OF EJS Templates
copyfile: add an optional parameter to copy other stat data...
Siddharth Agarwal -
r27369:c48ecc0b stable
parent child Browse files
Show More
@@ -806,8 +806,9 b' def checksignature(func):'
806
806
807 return check
807 return check
808
808
809 def copyfile(src, dest, hardlink=False):
809 def copyfile(src, dest, hardlink=False, copystat=False):
810 "copy a file, preserving mode and atime/mtime"
810 '''copy a file, preserving mode and optionally other stat info like
811 atime/mtime'''
811 if os.path.lexists(dest):
812 if os.path.lexists(dest):
812 unlink(dest)
813 unlink(dest)
813 # hardlinks are problematic on CIFS, quietly ignore this flag
814 # hardlinks are problematic on CIFS, quietly ignore this flag
@@ -820,10 +821,16 b' def copyfile(src, dest, hardlink=False):'
820 pass # fall back to normal copy
821 pass # fall back to normal copy
821 if os.path.islink(src):
822 if os.path.islink(src):
822 os.symlink(os.readlink(src), dest)
823 os.symlink(os.readlink(src), dest)
824 # copytime is ignored for symlinks, but in general copytime isn't needed
825 # for them anyway
823 else:
826 else:
824 try:
827 try:
825 shutil.copyfile(src, dest)
828 shutil.copyfile(src, dest)
826 shutil.copymode(src, dest)
829 if copystat:
830 # copystat also copies mode
831 shutil.copystat(src, dest)
832 else:
833 shutil.copymode(src, dest)
827 except shutil.Error as inst:
834 except shutil.Error as inst:
828 raise Abort(str(inst))
835 raise Abort(str(inst))
829
836
General Comments 0
You need to be logged in to leave comments. Login now