You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdelibs/tdeio/tdeio/README.xattr

88 lines
3.8 KiB

This is a small patch adding user extended attribute support[1] for local files
to tdeio. With the patch in place user xattrs are preserved when copying or
moving files on the local system[2]. It relies on libattr[3] to do the heavy
lifting.
The code adds a call to attr_copy_file in libattr that copies the user xattrs
from the source file to the destination file. The call is made after the
source file has been closed and immediately before the source file is deleted
(in the case that a move is being done). This code is based on the sample
code[4] provided with libattr (examples/copyattr.c).
This code has been in daily use by the author of this patch for just over five
years without any issues. What's missing though is the addition of tests for
xattr and libattr support at configuration/compile time. The code I've added
is enclosed by '#ifdef DO_USER_XATTR_COPYING' statements so a test should be
added that sets this macro[5] if configure-time tests show that xattrs/libattr
are working. I've added a preliminary test to CMakeLists.txt but I'm not sure
it's correct. Alternatively uncomment the '#define DO_USER_XATTR_COPYING 1'
statement at the top of the code to force my code to be enabled. Ensuring that
the cmake test working correctly needs to be done before general release.
This code has been tested on select Ubuntu Linux releases (natty, precise,
xenial, and jammy) using x86_64 Linux kernels 3.14.1, 4.18.3, and 5.15.0.
Tested filesystems are ext4 and squashfs.
As far as cross-platform availability goes this code is only known to work on
Linux[6][7]. That said, this code adds functionality that (as far as I'm aware)
isn't currently present in TDE on any of the platforms it runs on. In other
words, even if it only runs on Linux in its current state there is no loss of
functionality on any other platforms (just a lack of a gaining a feature). In
addition, determining the proper location to insert the library call was the
hard part with the actual implementation being quite straightforward. Adding
additional backends for other platforms should be pretty easy.
To test the code build and install it[8] then run the following from the
commandline in e.g. Konsole:
$ cd PATH_SUPPORTING_USER_XATTRS_AT_THE_FILESYSTEM_LEVEL
$ touch attr_test
$ setfattr -n "user.AttributeName" -v "Attribute value" attr_test
$ kfmclient copy attr_test attr_test.copy
$ getfattr -d attr_test*
The final command should output (minus the indents):
# file: attr_test
user.AttributeName="Attribute value"
# file: attr_test.copy
user.AttributeName="Attribute value"
Enjoy!
- Alex Kent Hajnal (AKH) 2022-12-21
[1] This includeds all attributes residing (on Linux) in the "user" namespace.
ACLs, etc. are not copied.
See the xattr(7) and e.g. the getfattr(1) manpages for more info.
[2] The underlying filesytems must, of course, have xattr support enabled.
This should be the case by default on modern systems that support xattrs.
[3] This is libattr1 and libattr1-dev on Ubuntu.
See http://savannah.nongnu.org/projects/attr for more info.
See also https://github.com/philips/attr
[4] The code that this patch is based on is licensed GPL v2 (or later).
[5] One has to use '#define DO_USER_XATTR_COPYING 1'; specifying instead
'#define DO_USER_XATTR_COPYING' doesn't enable the code (at least on my
system).
[6] I'm not sure which non-Linux platforms (if any) libattr runs on.
[7] Another known issue is namespaces. Linux, FreeBSD, and NetBSD support
xattrs using the 'user' namespace. Solaris and OSX support user xattrs
but do not support namespaces.
(source: File::ExtAttr(3pm), personal testing)
[8] Instead of doing a full install one can simply copy the updated library:
cp -va "BUILD_DIR/tdeio/libtdeio.so.14.0.0" /opt/trinity/lib/ && ldconfig