X Tutup
The Wayback Machine - https://web.archive.org/web/20260309033502/https://github.com/python/cpython/pull/14292
Skip to content

gh-81483: Add an "onerror" callback parameter to the tempfile.TemporaryDirectory member functions#14292

Closed
websurfer5 wants to merge 5 commits intopython:mainfrom
websurfer5:fix-issue-37302
Closed

gh-81483: Add an "onerror" callback parameter to the tempfile.TemporaryDirectory member functions#14292
websurfer5 wants to merge 5 commits intopython:mainfrom
websurfer5:fix-issue-37302

Conversation

@websurfer5
Copy link
Contributor

@websurfer5 websurfer5 commented Jun 21, 2019

This PR adds 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.

The provided test cases create a filesystem image and mount it within the temporary directory to force an error in the underlying shutil.rmtree() call during cleanup that triggers calls to the new onerror parameters. The test cases are provided for macOS because Windows and Linux require special user privileges to create and/or mount/unmount a filesystem image. This method was chosen to simulate the cleanup problems described in bpo-36422.

I am open to suggestions on how to force errors on those systems or in a portable manner. The usual trick of changing directory entry permissions won't work because tempfile.TemporaryDirectory() has heuristics to handle that case.

https://bugs.python.org/issue37302

Copy link
Member

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See recent changes to rmtree's onerror arg: #102829

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@erlend-aasland
Copy link
Contributor

@websurfer5 could you please resolve the conflicts and update the PR?

@erlend-aasland erlend-aasland added the pending The issue will be closed if no feedback is provided label Jan 5, 2024
@erlend-aasland erlend-aasland changed the title bpo-37302: Add an "onerror" callback parameter to the tempfile.TemporaryDirectory member functions gh-81483: Add an "onerror" callback parameter to the tempfile.TemporaryDirectory member functions Jan 5, 2024
@erlend-aasland
Copy link
Contributor

The feature request was rejected by @giampaolo in #80603 (comment). Closing.

@erlend-aasland erlend-aasland removed the pending The issue will be closed if no feedback is provided label Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

X Tutup