From 354ca28842e3796cb3161ded264ab5d92142aff2 Mon Sep 17 00:00:00 2001 From: Hugo Wallenburg Date: Sat, 4 Apr 2026 20:38:38 +0200 Subject: [PATCH] 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. --- src/borg/conftest.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/borg/conftest.py b/src/borg/conftest.py index 57b2dcbdaa..074ace1793 100644 --- a/src/borg/conftest.py +++ b/src/borg/conftest.py @@ -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()