Subject: bug#78623: cp --preserve=xattr copies attr as well as xattr which breaks cross-FS copy

From: Gael Donval <[email-masked]>
Date: Thu, 29 May 2025 09:56:07 +0000

On Thu, 2025-05-29 at 10:10 +0100, Pádraig Brady wrote:
> On 28/05/2025 16:14, Gael Donval wrote:
> > Dear list,
> > 
> > We've unearth an odd behaviour in cp: `cp --preserve=xattr` tries to copy both attributes of the chattr kind and extended attributes of the getfattr kind with apparently no way to disable either one of them (it's all or nothing). This is problematic in tools like mkosi where non-filesystem-specific xattributes need to be preserved whilst FS-specific attributes must be discarded for cross-filesystem support.
> > 
> > I have added a MWE at the end of this email after my signature: it creates two raw partitions as files (one as XFS, one as BTRFS), mounts them in local folders and creates 3 files in the BTRFS partitions later altered before copy.
> > 
> > Referring to the script, we think there should be an option to copy files foo (no-attr), bar (setfattr) and baz (chattr), keeping the setfattr's xattr and discarding chattr's attr. Looking at the code, it seems like cp eventually defers the actual attribute copying libattr, which seems to handle both, but separately (which is what we want).
> > 
> > Would it make sense to add a separate `attr` preserve value for the chattr case and keep `xattr` for getfattr case?
> 
> I've not looked in detail at your case,
> but it's worth noting that /etc/xattr.conf
> gives the facility to skip copying certain xattrs.
> Does that suffice to handle your issue?

As far as I can tell, xattr.conf cannot be used to ignore normal file
attributes (as opposed to extended attributes), can it? We need a way
to copy extended attributes without copying normal file attributes.

Thanks,
Gaël

> thanks,
> Pádraig