mirror of
https://git.rtems.org/rtems-source-builder
synced 2024-10-09 07:15:10 +08:00
Fix coping and delete on Windows.
This change uses a python.org feature to make the paths uicode which changes the WIN32 API used. The default WIN32 is limited to file lengths of 256 characters.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#
|
#
|
||||||
# RTEMS Tools Project (http://www.rtems.org/)
|
# RTEMS Tools Project (http://www.rtems.org/)
|
||||||
# Copyright 2010-2012 Chris Johns (chrisj@rtems.org)
|
# Copyright 2010-2015 Chris Johns (chrisj@rtems.org)
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# This file is part of the RTEMS Tools package in 'rtems-tools'.
|
# This file is part of the RTEMS Tools package in 'rtems-tools'.
|
||||||
@@ -128,6 +128,8 @@ def removeall(path):
|
|||||||
|
|
||||||
def _onerror(function, path, excinfo):
|
def _onerror(function, path, excinfo):
|
||||||
import stat
|
import stat
|
||||||
|
if windows:
|
||||||
|
path = "\\\\?\\" + path
|
||||||
if not os.access(path, os.W_OK):
|
if not os.access(path, os.W_OK):
|
||||||
# Is the error an access error ?
|
# Is the error an access error ?
|
||||||
os.chmod(path, stat.S_IWUSR)
|
os.chmod(path, stat.S_IWUSR)
|
||||||
@@ -147,20 +149,32 @@ def expand(name, paths):
|
|||||||
return l
|
return l
|
||||||
|
|
||||||
def copy_tree(src, dst):
|
def copy_tree(src, dst):
|
||||||
|
trace = False
|
||||||
|
|
||||||
hsrc = host(src)
|
hsrc = host(src)
|
||||||
hdst = host(dst)
|
hdst = host(dst)
|
||||||
|
|
||||||
if os.path.exists(src):
|
if os.path.exists(hsrc):
|
||||||
names = os.listdir(src)
|
names = os.listdir(hsrc)
|
||||||
else:
|
else:
|
||||||
names = []
|
names = []
|
||||||
|
|
||||||
if not os.path.isdir(dst):
|
if trace:
|
||||||
os.makedirs(dst)
|
print 'path.copy_tree:'
|
||||||
|
print ' src: %s' % (src)
|
||||||
|
print ' hsrc: %s' % (hsrc)
|
||||||
|
print ' dst: %s' % (dst)
|
||||||
|
print ' hdst: %s' % (hdst)
|
||||||
|
print ' names: %r' % (names)
|
||||||
|
|
||||||
|
if not os.path.isdir(hdst):
|
||||||
|
if trace:
|
||||||
|
print ' mkdir: %s' % (hdst)
|
||||||
|
os.makedirs(hdst)
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
srcname = os.path.join(src, name)
|
srcname = os.path.join(hsrc, name)
|
||||||
dstname = os.path.join(dst, name)
|
dstname = os.path.join(hdst, name)
|
||||||
try:
|
try:
|
||||||
if os.path.islink(srcname):
|
if os.path.islink(srcname):
|
||||||
linkto = os.readlink(srcname)
|
linkto = os.readlink(srcname)
|
||||||
@@ -179,20 +193,25 @@ def copy_tree(src, dst):
|
|||||||
os.symlink(linkto, dstname)
|
os.symlink(linkto, dstname)
|
||||||
elif os.path.isdir(srcname):
|
elif os.path.isdir(srcname):
|
||||||
copy_tree(srcname, dstname)
|
copy_tree(srcname, dstname)
|
||||||
|
else:
|
||||||
|
if windows:
|
||||||
|
shutil.copy2("\\\\?\\" + srcname, dstname)
|
||||||
else:
|
else:
|
||||||
shutil.copy2(srcname, dstname)
|
shutil.copy2(srcname, dstname)
|
||||||
except shutil.Error, err:
|
except shutil.Error, err:
|
||||||
raise error.general('copying tree: %s -> %s: %s' % (src, dst, str(err)))
|
raise error.general('copying tree: %s -> %s: %s' % \
|
||||||
|
(hsrc, hdst, str(err)))
|
||||||
except EnvironmentError, why:
|
except EnvironmentError, why:
|
||||||
raise error.general('copying tree: %s -> %s: %s' % (srcname, dstname, str(why)))
|
raise error.general('copying tree: %s -> %s: %s' % \
|
||||||
|
(srcname, dstname, str(why)))
|
||||||
try:
|
try:
|
||||||
shutil.copystat(src, dst)
|
shutil.copystat(hsrc, hdst)
|
||||||
except OSError, why:
|
except OSError, why:
|
||||||
if windows:
|
if windows:
|
||||||
if WindowsError is not None and isinstance(why, WindowsError):
|
if WindowsError is not None and isinstance(why, WindowsError):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise error.general('copying tree: %s -> %s: %s' % (src, dst, str(why)))
|
raise error.general('copying tree: %s -> %s: %s' % (hsrc, hdst, str(why)))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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