Fixes cleanup of append-only test tempfiles on macOS/BSD

The `test_extract_restores_append_flag` test leaves append-only
tempfiles around on macOS and FreeBSD that cannot be removed cleanly,
this was previously just ignored by the cleanup func but those files
occasionally caused lots of warning output on subsequent test runs.
Fixed by attempting to clear flags and retry whenever the cleanup
function fails.
This commit is contained in:
Hugo Wallenburg 2026-04-04 20:38:38 +02:00
parent 6959b69f9b
commit 354ca28842
No known key found for this signature in database

View file

@ -133,7 +133,21 @@ def archiver(tmp_path, set_env_variables):
os.chdir(archiver.tmpdir)
yield archiver
os.chdir(old_wd)
shutil.rmtree(archiver.tmpdir, ignore_errors=True) # clean up
def maybe_clear_flags_and_retry(func, path, _exc_info):
if has_lchflags:
# Clear any BSD flags (e.g. UF_APPEND) that may have prevented removal, then retry once.
try:
os.lchflags(path, 0)
func(path)
except OSError:
pass
else:
# Do nothing (equivalent to `ignore_errors=True`) if flags aren't supported on this platform.
pass
# Clean up archiver temp files
shutil.rmtree(archiver.tmpdir, onerror=maybe_clear_flags_and_retry)
@pytest.fixture()