diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-05-31 08:30:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-31 08:30:37 (GMT) |
commit | e9b51c0ad81da1da11ae65840ac8b50a8521373c (patch) | |
tree | 612f275e9aa504fdf3e5e18d736f19bf56fdb06f /Lib/shutil.py | |
parent | 38ab7d4721b422547f7b46b9d68968863fa70573 (diff) | |
download | cpython-e9b51c0ad81da1da11ae65840ac8b50a8521373c.zip cpython-e9b51c0ad81da1da11ae65840ac8b50a8521373c.tar.gz cpython-e9b51c0ad81da1da11ae65840ac8b50a8521373c.tar.bz2 |
bpo-26660, bpo-35144: Fix permission errors in TemporaryDirectory cleanup. (GH-10320)
TemporaryDirectory.cleanup() failed when non-writeable or non-searchable
files or directories were created inside a temporary directory.
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r-- | Lib/shutil.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index dae916b..6486cd6 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -584,11 +584,16 @@ def _rmtree_safe_fd(topfd, path, onerror): fullname = os.path.join(path, entry.name) try: is_dir = entry.is_dir(follow_symlinks=False) - if is_dir: - orig_st = entry.stat(follow_symlinks=False) - is_dir = stat.S_ISDIR(orig_st.st_mode) except OSError: is_dir = False + else: + if is_dir: + try: + orig_st = entry.stat(follow_symlinks=False) + is_dir = stat.S_ISDIR(orig_st.st_mode) + except OSError: + onerror(os.lstat, fullname, sys.exc_info()) + continue if is_dir: try: dirfd = os.open(entry.name, os.O_RDONLY, dir_fd=topfd) |