This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Jeffrey.Kintscher
Recipients Jeffrey.Kintscher, josh.r, riccardomurri
Date 2019-06-05.22:56:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1559775376.06.0.0439714460756.issue36422@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-06-05 22:56:16Jeffrey.Kintschersetrecipients: + Jeffrey.Kintscher, riccardomurri, josh.r
2019-06-05 22:56:16Jeffrey.Kintschersetmessageid: <1559775376.06.0.0439714460756.issue36422@roundup.psfhosted.org>
2019-06-05 22:56:16Jeffrey.Kintscherlinkissue36422 messages
2019-06-05 22:56:15Jeffrey.Kintschercreate