diff options
author | Barry Warsaw <barry@python.org> | 2003-01-24 17:36:15 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2003-01-24 17:36:15 (GMT) |
commit | 234d9a9eb390fc0975ca6fe8d010c45642bcdfed (patch) | |
tree | f0730e60fc05739fa8e4a6b9d678fe69ef146be5 /Lib/shutil.py | |
parent | 7fc2cca7d9056f6eacf7ccefdd136ed5f1496066 (diff) | |
download | cpython-234d9a9eb390fc0975ca6fe8d010c45642bcdfed.zip cpython-234d9a9eb390fc0975ca6fe8d010c45642bcdfed.tar.gz cpython-234d9a9eb390fc0975ca6fe8d010c45642bcdfed.tar.bz2 |
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.
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r-- | Lib/shutil.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index ad5c99d..f161c6a 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -117,27 +117,27 @@ def copytree(src, dst, symlinks=0): if 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. If ignore_errors is set, errors are ignored; otherwise, if onerror is set, it is called to handle the error; otherwise, an exception is raised. - """ cmdtuples = [] - _build_cmdtuple(path, cmdtuples) - for func, arg in cmdtuples: - try: + arg = path + try: + _build_cmdtuple(path, cmdtuples) + for func, arg in cmdtuples: func(arg) - except OSError: - exc = sys.exc_info() - if ignore_errors: - pass - elif onerror is not None: - onerror(func, arg, exc) - else: - raise exc[0], (exc[1][0], exc[1][1] + ' removing '+arg) + except OSError: + exc = sys.exc_info() + if ignore_errors: + pass + elif onerror is not None: + onerror(func, arg, exc) + else: + raise exc[0], (exc[1][0], exc[1][1] + ' removing '+arg) # Helper for rmtree() def _build_cmdtuple(path, cmdtuples): |