-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
shutil.rmtree using vagrant synched folder fails #83508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Python 3.6.9
Ubuntu 18.04
python3 -c 'import shutil; shutil.rmtree("1a")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.6/shutil.py", line 486, in rmtree
_rmtree_safe_fd(fd, path, onerror)
File "/usr/lib/python3.6/shutil.py", line 424, in _rmtree_safe_fd
_rmtree_safe_fd(dirfd, fullname, onerror)
File "/usr/lib/python3.6/shutil.py", line 424, in _rmtree_safe_fd
_rmtree_safe_fd(dirfd, fullname, onerror)
File "/usr/lib/python3.6/shutil.py", line 428, in _rmtree_safe_fd
onerror(os.rmdir, fullname, sys.exc_info())
File "/usr/lib/python3.6/shutil.py", line 426, in _rmtree_safe_fd
os.rmdir(name, dir_fd=topfd)
OSError: [Errno 26] Text file busy: '4a' Reproduction method |
Problem is also reported in virtualbox From that ticket some more analysis is done; |
I have encountered the same problem with vboxsf mounted folders when using Debian guest on VirtualBox 6.1 hosted by Windows 10. The general VirtualBox issue of vboxsf not supporting rmdir when there are open file descriptors is difficult to solve, and out of scope for Python. However, it looks like the shutil.rmtree implementation can be easily modified to change the order of operations so that the rmdir is performed after the directory file descriptor is closed, which makes shutil.rmtree work under vboxsf shared folders. Example of the change against Python 3.7 is inlined below. The changed order matches the behavior of "rm -r" and to my understanding should not change the security implications of the code, but as the code is related to the prevention of a symlink attack https://bugs.python.org/issue4489 careful review would be needed. --- /usr/lib/python3.7/shutil.py--orig 2021-01-23 05:04:44.000000000 +0900
+++ /usr/lib/python3.7/shutil.py 2021-12-09 20:42:36.795338346 +0900
@@ -427,10 +427,6 @@
try:
if os.path.samestat(orig_st, os.fstat(dirfd)):
_rmtree_safe_fd(dirfd, fullname, onerror)
- try:
- os.rmdir(entry.name, dir_fd=topfd)
- except OSError:
- onerror(os.rmdir, fullname, sys.exc_info())
else:
try:
# This can only happen if someone replaces
@@ -442,6 +438,10 @@
onerror(os.path.islink, fullname, sys.exc_info())
finally:
os.close(dirfd)
+ try:
+ os.rmdir(entry.name, dir_fd=topfd)
+ except OSError:
+ onerror(os.rmdir, fullname, sys.exc_info())
else:
try:
os.unlink(entry.name, dir_fd=topfd)
@@ -489,10 +489,6 @@
try:
if os.path.samestat(orig_st, os.fstat(fd)):
_rmtree_safe_fd(fd, path, onerror)
- try:
- os.rmdir(path)
- except OSError:
- onerror(os.rmdir, path, sys.exc_info())
else:
try:
# symlinks to directories are forbidden, see bug python/cpython#46010
@@ -501,6 +497,10 @@
onerror(os.path.islink, path, sys.exc_info())
finally:
os.close(fd)
+ try:
+ os.rmdir(path)
+ except OSError:
+ onerror(os.rmdir, path, sys.exc_info())
else:
try:
if os.path.islink(path): |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: