1124 |
1124 |
1125 def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None): |
1125 def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None): |
1126 """Copy a directory tree using hardlinks if possible.""" |
1126 """Copy a directory tree using hardlinks if possible.""" |
1127 num = 0 |
1127 num = 0 |
1128 |
1128 |
1129 if hardlink is None: |
|
1130 hardlink = (os.stat(src).st_dev == |
|
1131 os.stat(os.path.dirname(dst)).st_dev) |
|
1132 |
|
1133 gettopic = lambda: hardlink and _('linking') or _('copying') |
1129 gettopic = lambda: hardlink and _('linking') or _('copying') |
1134 topic = gettopic() |
|
1135 |
1130 |
1136 if os.path.isdir(src): |
1131 if os.path.isdir(src): |
|
1132 if hardlink is None: |
|
1133 hardlink = (os.stat(src).st_dev == |
|
1134 os.stat(os.path.dirname(dst)).st_dev) |
|
1135 topic = gettopic() |
1137 os.mkdir(dst) |
1136 os.mkdir(dst) |
1138 for name, kind in osutil.listdir(src): |
1137 for name, kind in osutil.listdir(src): |
1139 srcname = os.path.join(src, name) |
1138 srcname = os.path.join(src, name) |
1140 dstname = os.path.join(dst, name) |
1139 dstname = os.path.join(dst, name) |
1141 def nprog(t, pos): |
1140 def nprog(t, pos): |
1142 if pos is not None: |
1141 if pos is not None: |
1143 return progress(t, pos + num) |
1142 return progress(t, pos + num) |
1144 hardlink, n = copyfiles(srcname, dstname, hardlink, progress=nprog) |
1143 hardlink, n = copyfiles(srcname, dstname, hardlink, progress=nprog) |
1145 num += n |
1144 num += n |
1146 else: |
1145 else: |
|
1146 if hardlink is None: |
|
1147 hardlink = (os.stat(src).st_dev == |
|
1148 os.stat(os.path.dirname(dst)).st_dev) |
|
1149 topic = gettopic() |
|
1150 |
1147 if hardlink: |
1151 if hardlink: |
1148 try: |
1152 try: |
1149 oslink(src, dst) |
1153 oslink(src, dst) |
1150 except (IOError, OSError): |
1154 except (IOError, OSError): |
1151 hardlink = False |
1155 hardlink = False |