Skip to content

conftest: fix rmtree cleanup crash on Linux (os.lchflags does not exist) - #10124

Merged
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:fix-conftest-rmtree-linux
Aug 16, 2026
Merged

conftest: fix rmtree cleanup crash on Linux (os.lchflags does not exist)#10124
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:fix-conftest-rmtree-linux

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Member

The archiver fixture cleans up with shutil.rmtree(..., onerror=maybe_clear_flags_and_retry). That handler calls os.lchflags(path, 0) when has_lchflags is true, and retries the removal.

But has_lchflags is defined as:

has_lchflags = hasattr(os, "lchflags") or sys.platform.startswith("linux")

so it is also true on Linux, where flags are cleared via ioctl and os.lchflags does not exist. The resulting AttributeError is not an OSError, so it escapes the surrounding try/except OSError and turns teardown into an ERROR - the handler that exists to recover from a failed removal is itself broken on Linux.

Use borg's cross-platform platform.set_flags instead, which is the intended API and works on both BSD and Linux.

Split out of #9602 - the bug is independent of that PR and is present in master today.

@codecov

codecov Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.05%. Comparing base (91b030e) to head (54b1b3d).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10124   +/-   ##
=======================================
  Coverage   87.05%   87.05%           
=======================================
  Files         101      101           
  Lines       17848    17849    +1     
  Branches     2705     2705           
=======================================
+ Hits        15537    15539    +2     
+ Misses       1609     1608    -1     
  Partials      702      702           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

The archiver fixture's rmtree onerror handler called os.lchflags(path, 0)
when has_lchflags was True. But has_lchflags is also True on Linux (flags
are cleared via ioctl there), where os.lchflags does not exist, raising an
uncaught AttributeError and turning teardown into an ERROR. Use borg's
cross-platform platform.set_flags instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ThomasWaldmann
ThomasWaldmann force-pushed the fix-conftest-rmtree-linux branch from f350a99 to 54b1b3d Compare August 16, 2026 10:10
@ThomasWaldmann
ThomasWaldmann merged commit 25a4163 into borgbackup:master Aug 16, 2026
22 checks passed
@ThomasWaldmann
ThomasWaldmann deleted the fix-conftest-rmtree-linux branch August 16, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant