Jeffrey Kintscher <[email protected]> added the comment:
Only deleting from the local filesystem seems reasonable to me. In the context
of a temporary directory tree, I don't see a semantic difference between
"unmounting a mount point" and "removing a subdirectory entry" -- i.e. they
both remove the offending subdirectory tree from the temporary directory tree.
Internally, tempfile.TemporaryDirectory() calls shutil.rmtree() with a custom
error handler. The handler tries to reset the permissions on the offending
entry and calls os.unlink(). If this throws an error, it recursively calls
shutil.rmtree() on the offending entry (ignoring the temp directory entry
itself). This seems like where a mounted directory tree would get deleted.
shutil.rmtree() follows the "rm -rf" semantics and refuses to delete a mount
point. It seems reasonable to me to add special handling for mount points to
the error handler in tempfile.TemporaryDirectory(). The high-level logic would
be something like:
if os.path.ismount(path):
try:
unmount_func(path)
_shutil.rmtree(path)
except FileNotFoundError:
pass
The tricky part is implementing unmount_func() in a portable manner since there
is no such functionality currently implemented in the Python library.
Also, what would be the appropriate behavior when unmount_func() fails (e.g.
for a permission error)? Right now, any exceptions other than
IsADirectoryError, IsADirectoryError, and FileNotFoundError are passed on to
the caller.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36422>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com