Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Lib/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,13 +648,16 @@ def _rmtree_safe_fd(topfd, path, onerror):
if is_dir:
try:
dirfd = os.open(entry.name, os.O_RDONLY, dir_fd=topfd)
dirfd_closed = False
except OSError:
onerror(os.open, fullname, sys.exc_info())
else:
try:
if os.path.samestat(orig_st, os.fstat(dirfd)):
_rmtree_safe_fd(dirfd, fullname, onerror)
try:
os.close(dirfd)
dirfd_closed = True
os.rmdir(entry.name, dir_fd=topfd)
except OSError:
onerror(os.rmdir, fullname, sys.exc_info())
Expand All @@ -668,7 +671,8 @@ def _rmtree_safe_fd(topfd, path, onerror):
except OSError:
onerror(os.path.islink, fullname, sys.exc_info())
finally:
os.close(dirfd)
if not dirfd_closed:
os.close(dirfd)
else:
try:
os.unlink(entry.name, dir_fd=topfd)
Expand Down Expand Up @@ -711,13 +715,16 @@ def onerror(*args):
return
try:
fd = os.open(path, os.O_RDONLY)
fd_closed = False
except Exception:
onerror(os.open, path, sys.exc_info())
return
try:
if os.path.samestat(orig_st, os.fstat(fd)):
_rmtree_safe_fd(fd, path, onerror)
try:
os.close(fd)
fd_closed = True
os.rmdir(path)
except OSError:
onerror(os.rmdir, path, sys.exc_info())
Expand All @@ -728,7 +735,8 @@ def onerror(*args):
except OSError:
onerror(os.path.islink, path, sys.exc_info())
finally:
os.close(fd)
if not fd_closed:
os.close(fd)
else:
try:
if _rmtree_islink(path):
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ Caleb Deveraux
Catherine Devlin
Scott Dial
Alon Diamant
Lital Natan
Toby Dickenson
Mark Dickinson
Jack Diederich
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`shutil.rmtree` can now work with VirtualBox shared folders when
running from the guest operating-system.