Jeffrey Kintscher <websur...@surf2c.net> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36422>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to