Changeset 869b8a6 in rtems-source-builder


Ignore:
Timestamp:
Aug 15, 2013, 2:20:29 AM (7 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, 4.11, 4.9, master
Children:
407f7ff
Parents:
7a5f268
Message:

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.

Location:
source-builder/sb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • source-builder/sb/path.py

    r7a5f268 r869b8a6  
    139139    return l
    140140
     141def copy_tree(src, dst):
     142    hsrc = host(src)
     143    hdst = host(dst)
     144
     145    names = os.listdir(src)
     146
     147    if not os.path.isdir(dst):
     148        os.makedirs(dst)
     149
     150    for name in names:
     151        srcname = os.path.join(src, name)
     152        dstname = os.path.join(dst, name)
     153        try:
     154            if os.path.islink(srcname):
     155                linkto = os.readlink(srcname)
     156                os.symlink(linkto, dstname)
     157            elif os.path.isdir(srcname):
     158                copy_tree(srcname, dstname)
     159            else:
     160                shutil.copy2(srcname, dstname)
     161        except shutil.Error, err:
     162            raise error.general('copying tree: %s -> %s: %s' % (src, dst, str(err)))
     163        except EnvironmentError, why:
     164            raise error.general('copying tree: %s -> %s: %s' % (srcname, dstname, str(why)))
     165    try:
     166        shutil.copystat(src, dst)
     167    except OSError, why:
     168        if WindowsError is not None and isinstance(why, WindowsError):
     169            pass
     170        else:
     171            raise error.general('copying tree: %s -> %s: %s' % (src, dst, str(why)))
     172
    141173if __name__ == '__main__':
    142174    print host('/a/b/c/d-e-f')
  • source-builder/sb/setbuilder.py

    r7a5f268 r869b8a6  
    2525import copy
    2626import datetime
    27 import distutils.dir_util
    2827import glob
    2928import operator
     
    8483        log.output('copy: %s => %s' % (path.host(src), path.host(dst)))
    8584        if not self.opts.dry_run():
    86             if not os.path.isdir(path.host(src)):
    87                 raise error.general('copying tree: no source directory: %s' % \
    88                                         (path.host(src)))
    89             if not self.opts.dry_run():
    90                 try:
    91                     files = distutils.dir_util.copy_tree(path.host(src),
    92                                                          path.host(dst))
    93                     for f in files:
    94                         log.output(f)
    95                 except IOError, err:
    96                     raise error.general('copying tree: %s -> %s: %s' % (src, dst, str(err)))
    97                 except distutils.errors.DistutilsFileError, err:
    98                     raise error.general('copying tree: %s' % (str(err)))
     85            path.copy_tree(src, dst)
    9986
    10087    def report(self, _config, _build):
Note: See TracChangeset for help on using the changeset viewer.