mirror of
https://git.rtems.org/rtems-source-builder
synced 2024-10-09 07:15:10 +08:00
sb: Fix the copy tree.
Python's distutil's copy tree code maintains a cache of directories created so deleting a tree a different way then coping the same tree results in an error because the destination folders in the tree are not present because distutils thinks they exist. The solution is to implement a copy tree function.
This commit is contained in:
@@ -138,6 +138,38 @@ def expand(name, paths):
|
||||
l += [join(p, name)]
|
||||
return l
|
||||
|
||||
def copy_tree(src, dst):
|
||||
hsrc = host(src)
|
||||
hdst = host(dst)
|
||||
|
||||
names = os.listdir(src)
|
||||
|
||||
if not os.path.isdir(dst):
|
||||
os.makedirs(dst)
|
||||
|
||||
for name in names:
|
||||
srcname = os.path.join(src, name)
|
||||
dstname = os.path.join(dst, name)
|
||||
try:
|
||||
if os.path.islink(srcname):
|
||||
linkto = os.readlink(srcname)
|
||||
os.symlink(linkto, dstname)
|
||||
elif os.path.isdir(srcname):
|
||||
copy_tree(srcname, dstname)
|
||||
else:
|
||||
shutil.copy2(srcname, dstname)
|
||||
except shutil.Error, err:
|
||||
raise error.general('copying tree: %s -> %s: %s' % (src, dst, str(err)))
|
||||
except EnvironmentError, why:
|
||||
raise error.general('copying tree: %s -> %s: %s' % (srcname, dstname, str(why)))
|
||||
try:
|
||||
shutil.copystat(src, dst)
|
||||
except OSError, why:
|
||||
if WindowsError is not None and isinstance(why, WindowsError):
|
||||
pass
|
||||
else:
|
||||
raise error.general('copying tree: %s -> %s: %s' % (src, dst, str(why)))
|
||||
|
||||
if __name__ == '__main__':
|
||||
print host('/a/b/c/d-e-f')
|
||||
print host('//a/b//c/d-e-f')
|
||||
|
Reference in New Issue
Block a user