xattr: document fakeroot xattr as Linux-only, add missing fakeroot skip on FreeBSD, fixes #9394

This commit is contained in:
Mrityunjay Raj 2026-02-22 00:13:30 +05:30
parent 66051cc069
commit d1a10dd319
3 changed files with 14 additions and 5 deletions

View file

@ -2,10 +2,10 @@ import os
import tempfile
from ...platform import acl_get, acl_set
from .platform_test import skipif_not_freebsd, skipif_acls_not_working
from .platform_test import skipif_not_freebsd, skipif_fakeroot_detected, skipif_acls_not_working
# set module-level skips
pytestmark = [skipif_not_freebsd]
pytestmark = [skipif_not_freebsd, skipif_fakeroot_detected]
ACCESS_ACL = """\

View file

@ -3,7 +3,7 @@ import os
import pytest
from ..platform.xattr import buffer, split_lstring
from ..xattr import is_enabled, getxattr, setxattr, listxattr
from ..xattr import is_enabled, getxattr, setxattr, listxattr, XATTR_FAKEROOT
from ..platformflags import is_linux
@ -82,3 +82,11 @@ def test_getxattr_buffer_growth(tempfile_symlink):
)
def test_split_lstring(lstring, expected):
assert split_lstring(lstring) == expected
def test_xattr_fakeroot_flag():
"""XATTR_FAKEROOT must be False when not on Linux or when fakeroot is not active."""
if not is_linux:
assert XATTR_FAKEROOT is False
if "FAKEROOTKEY" not in os.environ:
assert XATTR_FAKEROOT is False

View file

@ -19,8 +19,9 @@ from .platform import listxattr, getxattr, setxattr, ENOATTR
# If we are running with fakeroot on Linux, then use the xattr functions of fakeroot. This is needed by
# the 'test_extract_capabilities' test, but also allows xattrs to work with fakeroot on Linux in normal use.
# TODO: Check whether fakeroot supports xattrs on all platforms supported below.
# TODO: If that's the case then we can make Borg fakeroot-xattr-compatible on these as well.
# Note: fakeroot xattr support is Linux-only. fakeroot only wraps the Linux-style setxattr/getxattr API,
# but FreeBSD/NetBSD use the extattr_* API instead, so fakeroot never intercepts xattr calls there.
# On macOS, fakeroot explicitly disables xattr wrapping due to prototype incompatibilities.
XATTR_FAKEROOT = False
if sys.platform.startswith("linux"):
LD_PRELOAD = os.environ.get("LD_PRELOAD", "")