TemporaryDirectory ignore_cleanup_errors flag is not robustic
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
Bug description:
When using ignore_cleanup_errors flag in TemporaryDirectory context manager, there's a path that will raise an issue.
In the onerror function that's being called when error in rmtree function:
If the first error is FileNotFound, pass
If it's everything else, check the ignore_errors flag, and raise if set to False
if the error was PermissionsError first try to change the permissions (the call to _resetperms , and then try to remove the files again. But the the call to resetparams is in an outer try, which is a lot weaker, and catching only the FileNotFoundError . But in our case, this very call raised PermissionError (yet again). It was not caught and raised back to our code.
Internal logs
2025-06-16 08:07:41 - ERROR - failed to solve strawman_local_enumeration: [Errno 1] Operation not permitted: '/tmp/tmpsrelpq9p/__pycache__'
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.11.8/x64/lib/python3.11/shutil.py", line 701, in _rmtree_safe_fd
os.unlink(entry.name, dir_fd=topfd)
PermissionError: [Errno 13] Permission denied: 'main.cpython-310.pyc'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/runner/work/CTF/CTF/src/solvers/solvers/solve_remote/solve_remote.py", line 212, in solve_remote_single
return solve_challenge_on_local_solver(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
File "/opt/hostedtoolcache/Python/3.11.8/x64/lib/python3.11/tempfile.py", line 287, in _resetperms
_dont_follow_symlinks(_os.chmod, path, 0o700)
File "/opt/hostedtoolcache/Python/3.11.8/x64/lib/python3.11/tempfile.py", line 278, in _dont_follow_symlinks
func(path, *args)
PermissionError: [Errno 1] Operation not permitted: '/tmp/tmpsrelpq9p/__pycache__'
CPython versions tested on:
3.11
Operating systems tested on:
macOS, Linux
Linked PRs
- gh-150696
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con _resetperms di tempfile.py e il percorso di pulizia di TemporaryDirectory, quindi confrontalo con la gestione di onerror di shutil.rmtree. Riproduci il caso PermissionError su Python 3.11 su macOS o Linux e aggiungi un test di regressione che dimostri che ignore_cleanup_errors impedisce all'errore di pulizia di propagarsi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- operating-systems
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100