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:
Chris Johns 2013-08-15 12:20:29 +10:00
parent 7a5f268d6a
commit 869b8a6bd3
2 changed files with 33 additions and 14 deletions

View File

@ -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')

View File

@ -24,7 +24,6 @@
import copy
import datetime
import distutils.dir_util
import glob
import operator
import os
@ -83,19 +82,7 @@ class buildset:
def copy(self, src, dst):
log.output('copy: %s => %s' % (path.host(src), path.host(dst)))
if not self.opts.dry_run():
if not os.path.isdir(path.host(src)):
raise error.general('copying tree: no source directory: %s' % \
(path.host(src)))
if not self.opts.dry_run():
try:
files = distutils.dir_util.copy_tree(path.host(src),
path.host(dst))
for f in files:
log.output(f)
except IOError, err:
raise error.general('copying tree: %s -> %s: %s' % (src, dst, str(err)))
except distutils.errors.DistutilsFileError, err:
raise error.general('copying tree: %s' % (str(err)))
path.copy_tree(src, dst)
def report(self, _config, _build):
if not _build.opts.get_arg('--no-report') \