rmtree(): Make implementation agree with documentation (both latex and

docstring).  Even if ignore_errors was true, an exception would occur
if path didn't exist.
This commit is contained in:
Barry Warsaw 2003-01-24 17:36:15 +00:00
parent 7fc2cca7d9
commit 234d9a9eb3
1 changed files with 13 additions and 13 deletions

View File

@ -117,27 +117,27 @@ def copytree(src, dst, symlinks=0):
if errors: if errors:
raise Error, errors raise Error, errors
def rmtree(path, ignore_errors=0, onerror=None): def rmtree(path, ignore_errors=False, onerror=None):
"""Recursively delete a directory tree. """Recursively delete a directory tree.
If ignore_errors is set, errors are ignored; otherwise, if If ignore_errors is set, errors are ignored; otherwise, if
onerror is set, it is called to handle the error; otherwise, an onerror is set, it is called to handle the error; otherwise, an
exception is raised. exception is raised.
""" """
cmdtuples = [] cmdtuples = []
_build_cmdtuple(path, cmdtuples) arg = path
for func, arg in cmdtuples: try:
try: _build_cmdtuple(path, cmdtuples)
for func, arg in cmdtuples:
func(arg) func(arg)
except OSError: except OSError:
exc = sys.exc_info() exc = sys.exc_info()
if ignore_errors: if ignore_errors:
pass pass
elif onerror is not None: elif onerror is not None:
onerror(func, arg, exc) onerror(func, arg, exc)
else: else:
raise exc[0], (exc[1][0], exc[1][1] + ' removing '+arg) raise exc[0], (exc[1][0], exc[1][1] + ' removing '+arg)
# Helper for rmtree() # Helper for rmtree()
def _build_cmdtuple(path, cmdtuples): def _build_cmdtuple(path, cmdtuples):