Skip to content

file flags: fix generic set_flags, keep unprivileged flags on EPERM, warn on failure - #10104

Draft
ThomasWaldmann wants to merge 3 commits into
borgbackup:masterfrom
ThomasWaldmann:flags-1345
Draft

file flags: fix generic set_flags, keep unprivileged flags on EPERM, warn on failure#10104
ThomasWaldmann wants to merge 3 commits into
borgbackup:masterfrom
ThomasWaldmann:flags-1345

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Member

Fixes #1345 (leftovers from the #9039 work).

  • platform.base.set_flags (used on NetBSD and generic POSIX) now also does the masked read-modify-write cycle instead of setting the archived value as-is. Before, a foreign flag bit made the whole lchflags call fail (losing all flags for that item) and a succeeding call clobbered flags that are not settable from userspace. The flag masks are defined once in platform.base now and shared by the freebsd/darwin implementations.
  • EPERM retry: if setting flags fails with EPERM (super-user-only SF_* flags while not running as root, or immutable/append-only on Linux without CAP_LINUX_IMMUTABLE), retry influencing only the unprivileged flags, so e.g. the nodump flag still gets restored by an unprivileged borg extract.
  • extract: emit a warning and set the warning exit code if the flags of an item cannot be set (was: silently ignored), consistent with the xattr error handling.
  • macOS set_flags: tolerate EOPNOTSUPP like the linux/freebsd implementations already do.
  • linux: remove the unused FS_COMPR_FL declaration.
  • new tests for the base implementation (faked lstat/lchflags, so they run on all platforms) and for the extract warning; docs section describing cross-platform behavior of file flags.

This answers the two questions from #1345: the flag sets do differ per platform (borg archives BSD-style values, translating on Linux), and extracting an item with flags unsupported on the destination platform drops only those flags — per-flag via the masks, and now also per-flag for flags that merely lack privileges. Only when flags cannot be set at all are the item's flags skipped, with a warning now.

🤖 Generated with Claude Code

…EPERM

- platform.base.set_flags (used on NetBSD and generic POSIX) now also does
  the masked read-modify-write cycle instead of setting the archived value
  as-is, see borgbackup#9039. The flag masks are defined once in platform.base and
  shared by the freebsd/darwin implementations.
- if setting the flags fails with EPERM (e.g. super-user-only SF_* flags
  while not running as root, or immutable/append-only on Linux without
  CAP_LINUX_IMMUTABLE), retry influencing only the unprivileged flags, so
  e.g. the nodump flag still gets restored, see borgbackup#1345.
- macOS: tolerate EOPNOTSUPP like the other platforms already do.
- linux: remove the unused FS_COMPR_FL declaration.
Previously, a failure to set the archived flags was silently ignored.
Now it emits a warning and sets the warning exit code, like xattr
errors already do.
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10104      +/-   ##
==========================================
+ Coverage   87.01%   87.05%   +0.04%     
==========================================
  Files          99      100       +1     
  Lines       17615    17684      +69     
  Branches     2664     2673       +9     
==========================================
+ Hits        15327    15395      +68     
  Misses       1593     1593              
- Partials      695      696       +1     

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

@ThomasWaldmann
ThomasWaldmann marked this pull request as draft August 14, 2026 14:46
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.

BSD flags: compatibility between platforms

1 participant