Commit c66760cc authored by PJ Eby's avatar PJ Eby

Fix rmtree() brokenness with Python 2.4 by breaking down and copying

shutil.rmtree from 2.4 directly into easy_install.py.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041402
parent f9aa7e9e
...@@ -106,7 +106,7 @@ class easy_install(Command): ...@@ -106,7 +106,7 @@ class easy_install(Command):
log.info("Deleting %s", filename) log.info("Deleting %s", filename)
if not self.dry_run: if not self.dry_run:
if os.path.isdir(filename) and not os.path.islink(filename): if os.path.isdir(filename) and not os.path.islink(filename):
shutil.rmtree(filename) rmtree(filename)
else: else:
os.unlink(filename) os.unlink(filename)
...@@ -318,7 +318,7 @@ class easy_install(Command): ...@@ -318,7 +318,7 @@ class easy_install(Command):
finally: finally:
if os.path.exists(tmpdir): if os.path.exists(tmpdir):
smart_rmtree(tmpdir) rmtree(tmpdir)
...@@ -856,7 +856,7 @@ See the setuptools documentation for the "develop" command for more info. ...@@ -856,7 +856,7 @@ See the setuptools documentation for the "develop" command for more info.
dist_dir) dist_dir)
return eggs return eggs
finally: finally:
shutil.rmtree(dist_dir) rmtree(dist_dir)
log.set_verbosity(self.verbose) # restore our log verbosity log.set_verbosity(self.verbose) # restore our log verbosity
def update_pth(self,dist): def update_pth(self,dist):
...@@ -1173,7 +1173,6 @@ def get_script_header(script_text): ...@@ -1173,7 +1173,6 @@ def get_script_header(script_text):
executable = os.path.normpath(sys.executable) executable = os.path.normpath(sys.executable)
return "#!%(executable)s%(options)s\n" % locals() return "#!%(executable)s%(options)s\n" % locals()
def main(argv=None, **kw): def main(argv=None, **kw):
from setuptools import setup from setuptools import setup
if argv is None: if argv is None:
...@@ -1181,46 +1180,47 @@ def main(argv=None, **kw): ...@@ -1181,46 +1180,47 @@ def main(argv=None, **kw):
setup(script_args = ['-q','easy_install', '-v']+argv, **kw) setup(script_args = ['-q','easy_install', '-v']+argv, **kw)
def auto_chmod(func, arg, exc):
if func is os.remove and os.name=='nt':
os.chmod(arg, stat.S_IWRITE)
return func(arg)
exc = sys.exc_info()
raise exc[0], (exc[1][0], exc[1][1] + (" %s %s" % (func,arg)))
def rmtree(path, ignore_errors=False, onerror=auto_chmod):
"""Recursively delete a directory tree.
This code is taken from the Python 2.4 version of 'shutil', because
the 2.3 version doesn't really work right.
"""
if ignore_errors:
def smart_rmtree(path): def onerror(*args):
"""Recursively delete a directory tree.""" pass
cmdtuples = [] elif onerror is None:
shutil._build_cmdtuple(path, cmdtuples) def onerror(*args):
for func, arg in cmdtuples: raise
names = []
try:
names = os.listdir(path)
except os.error, err:
onerror(os.listdir, path, sys.exc_info())
for name in names:
fullname = os.path.join(path, name)
try: try:
func(arg) mode = os.lstat(fullname).st_mode
except OSError: except os.error:
if os.name=='nt' and func is not os.rmdir: mode = 0
os.chmod(arg, stat.S_IWRITE) if stat.S_ISDIR(mode):
try: rmtree(fullname, ignore_errors, onerror)
func(arg) else:
continue try:
except OSError: os.remove(fullname)
pass except os.error, err:
exc = sys.exc_info() onerror(os.remove, fullname, sys.exc_info())
raise exc[0], (exc[1][0], exc[1][1] + ' removing '+arg) try:
os.rmdir(path)
except os.error:
onerror(os.rmdir, path, sys.exc_info())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment