diff options
author | Chris Johns <chrisj@rtems.org> | 2013-08-15 12:20:29 +1000 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2013-08-15 12:20:29 +1000 |
commit | 869b8a6bd33ae163518eef4ca017cc46881f20fc (patch) | |
tree | bf600d01170ce671d155fa24b646de2fb85dd74e /source-builder/sb/path.py | |
parent | doc: Add controlling the build. Add patch to cygwin. (diff) | |
download | rtems-source-builder-869b8a6bd33ae163518eef4ca017cc46881f20fc.tar.bz2 |
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.
Diffstat (limited to 'source-builder/sb/path.py')
-rw-r--r-- | source-builder/sb/path.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/source-builder/sb/path.py b/source-builder/sb/path.py index a14193f..643c08b 100644 --- a/source-builder/sb/path.py +++ b/source-builder/sb/path.py @@ -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') |