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-11.01:53:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1560218012.44.0.118398969054.issue36422@roundup.psfhosted.org>
In-reply-to
Content
tempfile.TemporaryDirectory() relies upon shutil.rmtree() to do the actual cleanup. Up through 3.7, it simply calls shutil.rmtree(). 3.8 adds some more logic using the onerror callback parameter of shutil.rmtree() to try changing the permissions on otherwise undeletable directory entries. In order to make tempfile.TemporaryDirectory() handle mount points, shutil.rmtree() requires some enhancements so that mount points can be detected before their contents are deleted.

I am working on some generic enhancements to tempfile.TemporaryDirectory() and shutil.rmtree() that add (hopefully) useful functionality that covers mount points as well as other corner cases:

1. Add an "onitem" callback paramter to shutil.rmtree() that, if provided, gets called for each directory entry as it is encountered. This allows the caller to perform any required special handling of individual directory entries (e.g. unmounting a mount point, closing a file, shutting down a named pipe, etc.).

2. Add an "onerror" callback parameter to the tempfile.TemporaryDirectory member functions so that the caller can perform special handling for directory items that it can't automatically delete. The caller created the undeletable directory entries, so it is reasonable to believe the caller may know how to unmake what they made.

3. Add an "onitem" callback parameter to the tempfile.TemporaryDirectory member functions that they pass on to shutil.rmtree().

I debated implementing "ondelete" instead of "onitem". "ondelete" would be called just prior to deleting an item, while "onitem" is called when the item is encountered. The difference in semantics is that a subdirectory entry triggers a call to "onitem" immediately, while "ondelete" would get called after the subdirectory tree had been traversed and all of its items deleted. "onitem" seems more useful because it allows the caller to implement special handling per item.

I will have a pull request ready soon. In the mean time, I am open to any other suggestions for handling non-portable corner cases.
History
Date User Action Args
2019-06-11 01:53:32Jeffrey.Kintschersetrecipients: + Jeffrey.Kintscher, riccardomurri, josh.r
2019-06-11 01:53:32Jeffrey.Kintschersetmessageid: <1560218012.44.0.118398969054.issue36422@roundup.psfhosted.org>
2019-06-11 01:53:32Jeffrey.Kintscherlinkissue36422 messages
2019-06-11 01:53:32Jeffrey.Kintschercreate