mirror of
https://github.com/borgbackup/borg.git
synced 2026-04-05 09:05:01 -04:00
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:
parent
6959b69f9b
commit
354ca28842
1 changed files with 15 additions and 1 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue