##// END OF EJS Templates
util: add progress callback support to copyfiles
Augie Fackler -
r24439:2ddfac2f default
parent child Browse files
Show More
@@ -739,20 +739,27 b' def copyfile(src, dest, hardlink=False):'
739 except shutil.Error, inst:
739 except shutil.Error, inst:
740 raise Abort(str(inst))
740 raise Abort(str(inst))
741
741
742 def copyfiles(src, dst, hardlink=None):
742 def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None):
743 """Copy a directory tree using hardlinks if possible"""
743 """Copy a directory tree using hardlinks if possible."""
744 num = 0
744
745
745 if hardlink is None:
746 if hardlink is None:
746 hardlink = (os.stat(src).st_dev ==
747 hardlink = (os.stat(src).st_dev ==
747 os.stat(os.path.dirname(dst)).st_dev)
748 os.stat(os.path.dirname(dst)).st_dev)
749 if hardlink:
750 topic = _('linking')
751 else:
752 topic = _('copying')
748
753
749 num = 0
750 if os.path.isdir(src):
754 if os.path.isdir(src):
751 os.mkdir(dst)
755 os.mkdir(dst)
752 for name, kind in osutil.listdir(src):
756 for name, kind in osutil.listdir(src):
753 srcname = os.path.join(src, name)
757 srcname = os.path.join(src, name)
754 dstname = os.path.join(dst, name)
758 dstname = os.path.join(dst, name)
755 hardlink, n = copyfiles(srcname, dstname, hardlink)
759 def nprog(t, pos):
760 if pos is not None:
761 return progress(t, pos + num)
762 hardlink, n = copyfiles(srcname, dstname, hardlink, progress=nprog)
756 num += n
763 num += n
757 else:
764 else:
758 if hardlink:
765 if hardlink:
@@ -764,6 +771,8 b' def copyfiles(src, dst, hardlink=None):'
764 else:
771 else:
765 shutil.copy(src, dst)
772 shutil.copy(src, dst)
766 num += 1
773 num += 1
774 progress(topic, num)
775 progress(topic, None)
767
776
768 return hardlink, num
777 return hardlink, num
769
778
General Comments 0
You need to be logged in to leave comments. Login now