summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/shutil.py12
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS.d/next/Library/2022-02-17-13-10-50.bpo-39327.ytIT7Z.rst2
3 files changed, 13 insertions, 2 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 0056a1b..37bf98d 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -646,6 +646,7 @@ 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:
@@ -653,6 +654,8 @@ def _rmtree_safe_fd(topfd, path, onerror):
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())
@@ -666,7 +669,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)
@@ -709,6 +713,7 @@ def rmtree(path, ignore_errors=False, onerror=None):
return
try:
fd = os.open(path, os.O_RDONLY)
+ fd_closed = False
except Exception:
onerror(os.open, path, sys.exc_info())
return
@@ -716,6 +721,8 @@ def rmtree(path, ignore_errors=False, onerror=None):
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())
@@ -726,7 +733,8 @@ def rmtree(path, ignore_errors=False, onerror=None):
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):
diff --git a/Misc/ACKS b/Misc/ACKS
index 4bd05b5..e107945 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -427,6 +427,7 @@ Caleb Deveraux
Catherine Devlin
Scott Dial
Alon Diamant
+Lital Natan
Toby Dickenson
Mark Dickinson
Jack Diederich
diff --git a/Misc/NEWS.d/next/Library/2022-02-17-13-10-50.bpo-39327.ytIT7Z.rst b/Misc/NEWS.d/next/Library/2022-02-17-13-10-50.bpo-39327.ytIT7Z.rst
new file mode 100644
index 0000000..fc6e825
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-02-17-13-10-50.bpo-39327.ytIT7Z.rst
@@ -0,0 +1,2 @@
+:func:`shutil.rmtree` can now work with VirtualBox shared folders when
+running from the guest operating-system.