summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Hajnal <trinitydesktop@alephnull.net>2022-12-26 01:31:36 -0500
committerAlexander Hajnal <trinitydesktop@alephnull.net>2022-12-26 01:42:42 -0500
commitb77dcf0a1491174dd7f64ac779d04fd2bd8caa1c (patch)
treea8450421ca5e78c14959c460191b659612a7dacf
parenta545725e86be1a5ae32ee41e8f4753f50fd6dd96 (diff)
downloadtdelibs-b77dcf0a1491174dd7f64ac779d04fd2bd8caa1c.tar.gz
tdelibs-b77dcf0a1491174dd7f64ac779d04fd2bd8caa1c.zip
Added test for libattr; Renamed macros
Signed-off-by: Alexander Hajnal <trinitydesktop@alephnull.net>
-rw-r--r--CMakeLists.txt9
-rw-r--r--tdeio/tdeio/README.xattr16
-rw-r--r--tdeio/tdeio/job.cpp13
3 files changed, 27 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 38ce5f045..84158ef6d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -284,6 +284,15 @@ if( NOT HAVE_SYS_UCRED_H )
endif( )
endif( )
check_include_file( "sys/xattr.h" HAVE_SYS_XATTR_H )
+check_include_file( "attr/libattr.h" HAVE_ATTR_LIBATTR_H)
+if ( HAVE_ATTR_LIBATTR_H )
+ check_library_exists( attr attr_copy_file "" HAVE_ATTR__ATTR_COPY_FILE )
+endif( )
+if( HAVE_ATTR__ATTR_COPY_FILE )
+ set( DO_USER_XATTR_COPYING "1" )
+ message( STATUS "User extended attribute copy support enabled" )
+endif( )
+
check_include_file( "termios.h" HAVE_TERMIOS_H )
check_include_file( "termio.h" HAVE_TERMIO_H )
check_include_file( "unistd.h" HAVE_UNISTD_H )
diff --git a/tdeio/tdeio/README.xattr b/tdeio/tdeio/README.xattr
index b1e37d3d0..50dcaf42b 100644
--- a/tdeio/tdeio/README.xattr
+++ b/tdeio/tdeio/README.xattr
@@ -12,11 +12,12 @@ 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 USE_XATTR' statements so a test should be added that
-sets this macro[5] if configure-time tests show that xattrs/libattr are working.
-I don't know how to go about adding such tests though so I've simply included a
-'#define USE_XATTR 1' statement to the top of the code. This should obviously
-be fixed before general release.
+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.
@@ -70,8 +71,9 @@ Enjoy!
[4] The code that this patch is based on is licensed GPL v2 (or later).
-[5] One has to use '#define USE_XATTR 1'; specifying '#define USE_XATTR'
- doesn't enable the code (at least on my system).
+[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.
diff --git a/tdeio/tdeio/job.cpp b/tdeio/tdeio/job.cpp
index 6f90bd213..a8e9e358a 100644
--- a/tdeio/tdeio/job.cpp
+++ b/tdeio/tdeio/job.cpp
@@ -82,15 +82,20 @@ extern "C" {
-// Set this macro if libattr is installed and working
-#define USE_XATTR 1
+// This macro is set if user extended attribute support is available.
+// Uncomment it here for testing purposes
+//#define DO_USER_XATTR_COPYING 1
+
+// To determine which backend is available check for the following macros:
+// HAVE_ATTR__ATTR_COPY_FILE -> attr_copy_file via libattr (Linux)
// Extended attribute support (added AKH 2017-11-26, updated AKH 2022-12-16)
// Based on copyattr.c by Andreas Gruenbacher (included with libattr)
// This does NOT also copy Access Control Lists!
-#ifdef USE_XATTR
+#ifdef DO_USER_XATTR_COPYING
+//#include <stdio.h> // For stderr, (v)fprintf (already included above)
//#include <errno.h> // For errno (already included above)
//#include <stdlib.h> // For free (already included above)
//#include <string.h> // For errno, strdup, and strcmp (already implictly included above)
@@ -2043,7 +2048,7 @@ void FileCopyJob::slotResult( TDEIO::Job *job)
{
m_copyJob = 0;
-#ifdef USE_XATTR
+#ifdef DO_USER_XATTR_COPYING
{
// Copy extended attributes (added AKH 2017-11-26)
attr_copy_file(TQFile::encodeName(m_src.path()), TQFile::encodeName(m_dest.path()), NULL, &ctx);