Changeset 78c1524 in rtems-source-builder


Ignore:
Timestamp:
Jun 7, 2017, 5:00:13 AM (2 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.11
Children:
d57380a
Parents:
2433c4b
git-author:
Chris Johns <chrisj@…> (06/07/17 05:00:13)
git-committer:
Chris Johns <chrisj@…> (06/14/17 01:22:50)
Message:

sb: Fix long path support in the copy_tree and removeall path support.

This change lets the LM32 target build on Windows which has temporary
install paths greated than the Win32 API max size. The buildroot path
compression is still needed as the GNU assembler does not like paths
that exceed the max Windows limit.

Closes #2992.

File:
1 edited

Legend:

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

    r2433c4b r78c1524  
    3535
    3636windows = os.name == 'nt'
     37win_maxpath = 254
    3738
    3839def host(path):
     
    4748                path = '%s:%s' % (path[1], path[2:])
    4849            path = path.replace('/', '\\')
    49             if not path.startswith('\\\\?\\') and len(path) > 254:
    50                 path = '\\\\?\\' + path
     50            if len(path) > win_maxpath:
     51                if path.startswith('\\\\?\\'):
     52                    path = path[4:]
     53                path = u'\\'.join([u'\\\\?', path])
    5154    return path
    5255
     
    5457    if path is not None:
    5558        if windows:
     59            path = path.encode('ascii', 'ignore')
    5660            if path.startswith('\\\\?\\'):
    5761                path = path[4:]
     
    8589    return shell(root), ext
    8690
     91def listdir(path):
     92    hp = host(path)
     93    if not os.path.exists(hp):
     94        return []
     95    return os.listdir(hp)
     96
    8797def exists(paths):
     98    def _exists(p):
     99        return os.path.basename(p) in listdir(dirname(p))
     100
    88101    if type(paths) == list:
    89102        results = []
    90103        for p in paths:
    91             results += [os.path.exists(host(p))]
     104            results += [_exists(p)]
    92105        return results
    93     return os.path.exists(host(paths))
     106    return _exists(paths)
    94107
    95108def isdir(path):
     
    108121    path = host(path)
    109122    while len(path) != 0:
    110         if os.path.exists(path):
     123        if exists(path):
    111124            return iswritable(path)
    112125        path = os.path.dirname(path)
     
    136149                raise error.general('cannot make directory: %s' % (path))
    137150
     151def chdir(path):
     152    os.chdir(host(path))
     153
    138154def removeall(path):
    139155    #
    140156    # Perform the removal of the directory tree manually so we can
    141     # make sure on Windows the files and correctly encoded to avoid
    142     # the size limit.
     157    # make sure on Windows the files are correctly encoded to avoid
     158    # the file name size limit. On Windows the os.walk fails once we
     159    # get to the max path length on Windows.
    143160    #
    144     path = host(path)
    145     for root, dirs, files in os.walk(path, topdown = False):
    146         for name in files:
    147             file = host(os.path.join(root, name))
    148             if not os.path.islink(file) and not os.access(file, os.W_OK):
    149                 os.chmod(file, stat.S_IWUSR)
    150             os.unlink(file)
     161    def _isdir(path):
     162        hpath = host(path)
     163        return os.path.isdir(hpath) and not os.path.islink(hpath)
     164
     165    def _remove_node(path):
     166        hpath = host(path)
     167        if not os.path.islink(hpath) and not os.access(hpath, os.W_OK):
     168            os.chmod(hpath, stat.S_IWUSR)
     169        if _isdir(path):
     170            os.rmdir(hpath)
     171        else:
     172            os.unlink(hpath)
     173
     174    def _remove(path):
     175        dirs = []
     176        for name in listdir(path):
     177            path_ = join(path, name)
     178            hname = host(path_)
     179            if _isdir(path_):
     180                dirs += [name]
     181            else:
     182                _remove_node(path_)
    151183        for name in dirs:
    152             dir = host(os.path.join(root, name))
    153             if os.path.islink(dir):
    154                 os.unlink(dir)
    155             else:
    156                 if not os.access(dir, os.W_OK):
    157                     os.chmod(dir, stat.S_IWUSR)
    158                 os.rmdir(dir)
    159     if not os.path.islink(path) and not os.access(path, os.W_OK):
    160         os.chmod(path, stat.S_IWUSR)
    161     if os.path.islink(path):
    162         os.unlink(path)
    163     else:
    164         os.rmdir(path)
     184            dir = join(path, name)
     185            _remove(dir)
     186            _remove_node(dir)
     187
     188    hpath = host(path)
     189
     190    if os.path.exists(hpath):
     191        _remove(path)
     192        _remove_node(path)
    165193
    166194def expand(name, paths):
     
    188216    hdst = host(dst)
    189217
    190     if os.path.exists(hsrc):
    191         names = os.listdir(hsrc)
     218    if exists(hsrc):
     219        names = listdir(hsrc)
    192220    else:
    193221        names = []
     
    195223    if trace:
    196224        print('path.copy_tree:')
    197         print('   src: %s' % (src))
    198         print('  hsrc: %s' % (hsrc))
    199         print('   dst: %s' % (dst))
    200         print('  hdst: %s' % (hdst))
     225        print('   src: "%s"' % (src))
     226        print('  hsrc: "%s"' % (hsrc))
     227        print('   dst: "%s"' % (dst))
     228        print('  hdst: "%s"' % (hdst))
    201229        print(' names: %r' % (names))
    202230
     
    216244            if os.path.islink(srcname):
    217245                linkto = os.readlink(srcname)
    218                 if os.path.exists(dstname):
     246                if exists(dstname):
    219247                    if os.path.islink(dstname):
    220248                        dstlinkto = os.readlink(dstname)
     
    232260                copy_tree(srcname, dstname)
    233261            else:
    234                     shutil.copy2(host(srcname), host(dstname))
     262                shutil.copyfile(host(srcname), host(dstname))
     263                shutil.copystat(host(srcname), host(dstname))
    235264        except shutil.Error as err:
    236265            raise error.general('copying tree: %s -> %s: %s' % \
Note: See TracChangeset for help on using the changeset viewer.