From b25f2a37e5dbd3e452a88f2d05be9733397a7d94 Mon Sep 17 00:00:00 2001 From: medoc Date: Mon, 15 Jul 2013 22:35:04 +0200 Subject: [PATCH] get recoll non-gui parts to build under cygwin --- src/configure | 150 ++++++++++++++---- src/configure.ac | 30 +++- src/lib/Makefile | 2 +- src/mk/CYGWIN | 10 ++ src/utils/pxattr.cpp | 352 ++++++++++++++++++++++++++++--------------- 5 files changed, 385 insertions(+), 159 deletions(-) create mode 100644 src/mk/CYGWIN diff --git a/src/configure b/src/configure index ff0148c6..46f9ca69 100755 --- a/src/configure +++ b/src/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for Recoll 1.19.0. +# Generated by GNU Autoconf 2.69 for Recoll 1.19.5. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -577,8 +577,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='Recoll' PACKAGE_TARNAME='recoll' -PACKAGE_VERSION='1.19.0' -PACKAGE_STRING='Recoll 1.19.0' +PACKAGE_VERSION='1.19.5' +PACKAGE_STRING='Recoll 1.19.5' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -652,7 +652,9 @@ X_CFLAGS CXXCPP XMKMF QMAKEPATH -XAPIAN_CONFIG +XAPIAN_CONFIG2 +XAPIAN_CONFIG1 +XAPIAN_CONFIG0 aspellProg fileProg EGREP @@ -1279,7 +1281,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures Recoll 1.19.0 to adapt to many kinds of systems. +\`configure' configures Recoll 1.19.5 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1344,7 +1346,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of Recoll 1.19.0:";; + short | recursive ) echo "Configuration of Recoll 1.19.5:";; esac cat <<\_ACEOF @@ -1473,7 +1475,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -Recoll configure 1.19.0 +Recoll configure 1.19.5 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2026,7 +2028,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by Recoll $as_me 1.19.0, which was +It was created by Recoll $as_me 1.19.5, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2890,7 +2892,7 @@ if test C$CXX = C ; then as_fn_error $? "C++ compiler needed. Please install one (ie: gnu g++)" "$LINENO" 5 fi -sys=`uname | tr / _` +sys=`uname | tr / _ | awk -F_ '{print $1}'` if test ! -f mk/$sys ; then { $as_echo "$as_me:${as_lineno-$LINENO}: @@ -4452,12 +4454,12 @@ ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ex ac_compiler_gnu=$ac_cv_cxx_compiler_gnu LIBICONV="" -S_LDFLAGS=$LDFLAGS +S_LIBS=$LIBS S_CPPFLAGS=$CPPFLAGS -for dir in ${libdir} /opt/local/lib /usr/local/lib ;do +for dir in ${libdir} /opt/local/lib /usr/local/lib;do CPPFLAGS="$S_CPPFLAGS -I$dir/../include" - LDFLAGS="$S_LDFLAGS -L$dir" + LIBS="$S_LIBS -L$dir" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -4482,7 +4484,7 @@ rm -f core conftest.err conftest.$ac_objext \ break fi - LDFLAGS="$S_LDFLAGS -L$dir -liconv" + LIBS="$S_LIBS -L$dir -liconv" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include @@ -4508,7 +4510,7 @@ rm -f core conftest.err conftest.$ac_objext \ done -LDFLAGS=$S_LDFLAGS +LIBS=$S_LIBS CPPFLAGS=$S_CPPFLAGS if test A"$LIBICONV" = A ; then @@ -4581,17 +4583,20 @@ $as_echo "#define PUTENV_ARG_CONST 1" >>confdefs.h fi -#### Look for Xapian -# Extract the first word of "xapian-config", so it can be a program name with args. +#### Look for Xapian. Done in a strange way to work around autoconf +# cache +XAPIAN_CONFIG=no +if test "$XAPIAN_CONFIG" = "no"; then + # Extract the first word of "xapian-config", so it can be a program name with args. set dummy xapian-config; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_path_XAPIAN_CONFIG+:} false; then : +if ${ac_cv_path_XAPIAN_CONFIG0+:} false; then : $as_echo_n "(cached) " >&6 else - case $XAPIAN_CONFIG in + case $XAPIAN_CONFIG0 in [\\/]* | ?:[\\/]*) - ac_cv_path_XAPIAN_CONFIG="$XAPIAN_CONFIG" # Let the user override the test with a path. + ac_cv_path_XAPIAN_CONFIG0="$XAPIAN_CONFIG0" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -4601,7 +4606,7 @@ do test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_path_XAPIAN_CONFIG="$as_dir/$ac_word$ac_exec_ext" + ac_cv_path_XAPIAN_CONFIG0="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi @@ -4609,20 +4614,111 @@ done done IFS=$as_save_IFS - test -z "$ac_cv_path_XAPIAN_CONFIG" && ac_cv_path_XAPIAN_CONFIG="no" + test -z "$ac_cv_path_XAPIAN_CONFIG0" && ac_cv_path_XAPIAN_CONFIG0="no" ;; esac fi -XAPIAN_CONFIG=$ac_cv_path_XAPIAN_CONFIG -if test -n "$XAPIAN_CONFIG"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XAPIAN_CONFIG" >&5 -$as_echo "$XAPIAN_CONFIG" >&6; } +XAPIAN_CONFIG0=$ac_cv_path_XAPIAN_CONFIG0 +if test -n "$XAPIAN_CONFIG0"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XAPIAN_CONFIG0" >&5 +$as_echo "$XAPIAN_CONFIG0" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi + XAPIAN_CONFIG=$XAPIAN_CONFIG0 +fi +if test "$XAPIAN_CONFIG" = "no"; then + # Extract the first word of "xapian-config-1.3", so it can be a program name with args. +set dummy xapian-config-1.3; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_XAPIAN_CONFIG1+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $XAPIAN_CONFIG1 in + [\\/]* | ?:[\\/]*) + ac_cv_path_XAPIAN_CONFIG1="$XAPIAN_CONFIG1" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_XAPIAN_CONFIG1="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_path_XAPIAN_CONFIG1" && ac_cv_path_XAPIAN_CONFIG1="no" + ;; +esac +fi +XAPIAN_CONFIG1=$ac_cv_path_XAPIAN_CONFIG1 +if test -n "$XAPIAN_CONFIG1"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XAPIAN_CONFIG1" >&5 +$as_echo "$XAPIAN_CONFIG1" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + XAPIAN_CONFIG=$XAPIAN_CONFIG1 +fi +if test "$XAPIAN_CONFIG" = "no"; then + # Extract the first word of "xapian-config-1.1", so it can be a program name with args. +set dummy xapian-config-1.1; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_XAPIAN_CONFIG2+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $XAPIAN_CONFIG2 in + [\\/]* | ?:[\\/]*) + ac_cv_path_XAPIAN_CONFIG2="$XAPIAN_CONFIG2" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_XAPIAN_CONFIG2="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_path_XAPIAN_CONFIG2" && ac_cv_path_XAPIAN_CONFIG2="no" + ;; +esac +fi +XAPIAN_CONFIG2=$ac_cv_path_XAPIAN_CONFIG2 +if test -n "$XAPIAN_CONFIG2"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XAPIAN_CONFIG2" >&5 +$as_echo "$XAPIAN_CONFIG2" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + XAPIAN_CONFIG=$XAPIAN_CONFIG2 +fi + if test "$XAPIAN_CONFIG" = "no" ; then as_fn_error $? "Cannot find xapian-config command in $PATH. Is xapian-core installed ?" "$LINENO" 5 @@ -6259,7 +6355,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by Recoll $as_me 1.19.0, which was +This file was extended by Recoll $as_me 1.19.5, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -6321,7 +6417,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -Recoll config.status 1.19.0 +Recoll config.status 1.19.5 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/src/configure.ac b/src/configure.ac index b322e1a1..999d5f80 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -8,7 +8,7 @@ if test C$CXX = C ; then AC_MSG_ERROR([C++ compiler needed. Please install one (ie: gnu g++)]) fi -sys=`uname | tr / _` +sys=`uname | tr / _ | awk -F_ '{print $1}'` if test ! -f mk/$sys ; then AC_MSG_NOTICE([ @@ -251,12 +251,12 @@ AC_CHECK_FUNCS(mkdtemp) ##### libiconv. We'd need a --with-libiconv= option AC_LANG(C++) LIBICONV="" -S_LDFLAGS=$LDFLAGS +S_LIBS=$LIBS S_CPPFLAGS=$CPPFLAGS -for dir in ${libdir} /opt/local/lib /usr/local/lib ;do +for dir in ${libdir} /opt/local/lib /usr/local/lib;do CPPFLAGS="$S_CPPFLAGS -I$dir/../include" - LDFLAGS="$S_LDFLAGS -L$dir" + LIBS="$S_LIBS -L$dir" AC_TRY_LINK([#include #include ], [iconv_t cd = iconv_open("",""); @@ -267,7 +267,7 @@ for dir in ${libdir} /opt/local/lib /usr/local/lib ;do break fi - LDFLAGS="$S_LDFLAGS -L$dir -liconv" + LIBS="$S_LIBS -L$dir -liconv" AC_TRY_LINK([#include #include ], [iconv_t cd = iconv_open("",""); @@ -280,7 +280,7 @@ for dir in ${libdir} /opt/local/lib /usr/local/lib ;do done -LDFLAGS=$S_LDFLAGS +LIBS=$S_LIBS CPPFLAGS=$S_CPPFLAGS if test A"$LIBICONV" = A ; then @@ -315,8 +315,22 @@ if test X$rcl_putenv_string_const = X1 ; then fi -#### Look for Xapian -AC_PATH_PROG(XAPIAN_CONFIG, xapian-config, no) +#### Look for Xapian. Done in a strange way to work around autoconf +# cache +XAPIAN_CONFIG=no +if test "$XAPIAN_CONFIG" = "no"; then + AC_PATH_PROG(XAPIAN_CONFIG0, [xapian-config], no) + XAPIAN_CONFIG=$XAPIAN_CONFIG0 +fi +if test "$XAPIAN_CONFIG" = "no"; then + AC_PATH_PROG(XAPIAN_CONFIG1, [xapian-config-1.3], no) + XAPIAN_CONFIG=$XAPIAN_CONFIG1 +fi +if test "$XAPIAN_CONFIG" = "no"; then + AC_PATH_PROG(XAPIAN_CONFIG2, [xapian-config-1.1], no) + XAPIAN_CONFIG=$XAPIAN_CONFIG2 +fi + if test "$XAPIAN_CONFIG" = "no" ; then AC_MSG_ERROR([Cannot find xapian-config command in $PATH. Is xapian-core installed ?]) diff --git a/src/lib/Makefile b/src/lib/Makefile index 9d030a4d..cd685045 100644 --- a/src/lib/Makefile +++ b/src/lib/Makefile @@ -4,7 +4,7 @@ include $(depth)/mk/sysconf LIBRECOLL=librecoll.so.$(RCLLIBVERSION) LIBS = librecoll.a -LIBS = librecoll.a $(LIBRECOLL) +#LIBS = librecoll.a $(LIBRECOLL) all: $(LIBS) diff --git a/src/mk/CYGWIN b/src/mk/CYGWIN new file mode 100644 index 00000000..0112ae61 --- /dev/null +++ b/src/mk/CYGWIN @@ -0,0 +1,10 @@ + +include $(depth)/mk/commondefs +include $(depth)/mk/localdefs + +ALL_CXXFLAGS = $(CXXFLAGS) $(COMMONCXXFLAGS) $(LOCALCXXFLAGS) \ + -D_GNU_SOURCE + +LIBSYS = -lpthread -ldl +LIBSYSTHREADS = + diff --git a/src/utils/pxattr.cpp b/src/utils/pxattr.cpp index 030d22d5..76cb8e5d 100644 --- a/src/utils/pxattr.cpp +++ b/src/utils/pxattr.cpp @@ -23,9 +23,14 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/** \file pxattr.cpp + \brief This is a comment for file pxattr.cpp + */ + // We want this to compile even to empty on non-supported systems. makes // things easier for autoconf -#if defined(__FreeBSD__) || defined(__gnu_linux__) || defined(__APPLE__) +#if defined(__FreeBSD__) || defined(__gnu_linux__) || defined(__APPLE__) || \ + defined(__CYGWIN32__) #ifndef TEST_PXATTR @@ -39,6 +44,8 @@ OTHER DEALINGS IN THE SOFTWARE. #include #elif defined(__gnu_linux__) #include +#elif defined(__CYGWIN32__) +#include #elif defined(__APPLE__) #include #else @@ -489,128 +496,7 @@ using namespace std; #include "pxattr.h" -static void dotests() -{ - static const char *tfn = "pxattr_testtmp.xyz"; - static const char *NAMES[] = {"ORG.PXATTR.NAME1", "ORG.PXATTR.N2", - "ORG.PXATTR.LONGGGGGGGGisSSSHHHHHHHHHNAME3"}; - static const char *VALUES[] = {"VALUE1", "VALUE2", "VALUE3"}; - static bool verbose = true; - - /* Create test file if it doesn't exist, remove all attributes */ - int fd = open(tfn, O_RDWR|O_CREAT, 0755); - if (fd < 0) { - perror("open/create"); - exit(1); - } - - - if (verbose) - fprintf(stdout, "Cleanup old attrs\n"); - vector names; - if (!pxattr::list(tfn, &names)) { - perror("pxattr::list"); - exit(1); - } - for (vector::const_iterator it = names.begin(); - it != names.end(); it++) { - string value; - if (!pxattr::del(fd, *it)) { - perror("pxattr::del"); - exit(1); - } - } - /* Check that there are no attributes left */ - names.clear(); - if (!pxattr::list(tfn, &names)) { - perror("pxattr::list"); - exit(1); - } - if (names.size() != 0) { - fprintf(stderr, "Attributes remain after initial cleanup !\n"); - for (vector::const_iterator it = names.begin(); - it != names.end(); it++) { - fprintf(stderr, "%s\n", (*it).c_str()); - } - exit(1); - } - - /* Create attributes, check existence and value */ - if (verbose) - fprintf(stdout, "Creating extended attributes\n"); - for (int i = 0; i < 3; i++) { - if (!pxattr::set(fd, NAMES[i], VALUES[i])) { - perror("pxattr::set"); - exit(1); - } - } - if (verbose) - fprintf(stdout, "Checking creation\n"); - for (int i = 0; i < 3; i++) { - string value; - if (!pxattr::get(tfn, NAMES[i], &value)) { - perror("pxattr::get"); - exit(1); - } - if (value.compare(VALUES[i])) { - fprintf(stderr, "Wrong value after create !\n"); - exit(1); - } - } - - /* Delete one, check list */ - if (verbose) - fprintf(stdout, "Delete one\n"); - if (!pxattr::del(tfn, NAMES[1])) { - perror("pxattr::del one name"); - exit(1); - } - if (verbose) - fprintf(stdout, "Check list\n"); - for (int i = 0; i < 3; i++) { - string value; - if (!pxattr::get(fd, NAMES[i], &value)) { - if (i == 1) - continue; - perror("pxattr::get"); - exit(1); - } else if (i == 1) { - fprintf(stderr, "Name at index 1 still exists after deletion\n"); - exit(1); - } - if (value.compare(VALUES[i])) { - fprintf(stderr, "Wrong value after delete 1 !\n"); - exit(1); - } - } - - /* Test the CREATE/REPLACE flags */ - // Set existing with flag CREATE should fail - if (verbose) - fprintf(stdout, "Testing CREATE/REPLACE flags use\n"); - if (pxattr::set(tfn, NAMES[0], VALUES[0], pxattr::PXATTR_CREATE)) { - fprintf(stderr, "Create existing with flag CREATE succeeded !\n"); - exit(1); - } - // Set new with flag REPLACE should fail - if (pxattr::set(tfn, NAMES[1], VALUES[1], pxattr::PXATTR_REPLACE)) { - fprintf(stderr, "Create new with flag REPLACE succeeded !\n"); - exit(1); - } - // Set new with flag CREATE should succeed - if (!pxattr::set(fd, NAMES[1], VALUES[1], pxattr::PXATTR_CREATE)) { - fprintf(stderr, "Create new with flag CREATE failed !\n"); - exit(1); - } - // Set existing with flag REPLACE should succeed - if (!pxattr::set(fd, NAMES[0], VALUES[0], pxattr::PXATTR_REPLACE)) { - fprintf(stderr, "Create existing with flag REPLACE failed !\n"); - exit(1); - } - close(fd); - unlink(tfn); - exit(0); -} +static void dotests(); // \-quote character c in input \ -> \\, nl -> \n cr -> \rc -> \c static void quote(const string& in, string& out, int c) @@ -938,7 +824,227 @@ int main(int argc, char **argv) exit(0); } +static void fatal(const string& s) +{ + perror(s.c_str()); + exit(1); +} +static bool testbackups() +{ + static const char *top = "ttop"; + static const char *d1 = "d1"; + static const char *d2 = "d2"; + static const char *tfn1 = "tpxattr1.txt"; + static const char *tfn2 = "tpxattr2.txt"; + static const char *dump = "attrdump.txt"; + static const char *NAMES[] = {"ORG.PXATTR.NAME1", + "ORG=PXATTR\"=\\=\n", + "=", "Name4"}; + static const char *VALUES[] = + {"VALUE1", "VALUE2", "VALUE3=VALUE3equal", + "VALUE4\n is more like" + " normal text\n with new lines and \"\\\" \\\" backslashes"}; + + static const int nattrs = sizeof(NAMES) / sizeof(char *); + + if (mkdir(top, 0777)) + fatal("Cant mkdir ttop"); + if (chdir(top)) + fatal("cant chdir ttop"); + if (mkdir(d1, 0777) || mkdir(d2, 0777)) + fatal("Can't mkdir ttdop/dx\n"); + if (chdir(d1)) + fatal("chdir d1"); + + int fd; + if ((fd = open(tfn1, O_RDWR|O_CREAT, 0755)) < 0) + fatal("create d1/tpxattr1.txt"); + /* Set attrs */ + for (int i = 0; i < nattrs; i++) { + if (!pxattr::set(fd, NAMES[i], VALUES[i])) + fatal("pxattr::set"); + } + close(fd); + if ((fd = open(tfn2, O_RDWR|O_CREAT, 0755)) < 0) + fatal("create d1/tpxattr2.txt"); + /* Set attrs */ + for (int i = 0; i < nattrs; i++) { + if (!pxattr::set(fd, NAMES[i], VALUES[i])) + fatal("pxattr::set"); + } + close(fd); + + /* Create dump */ + string cmd; + cmd = string("pxattr -lR . > " ) + dump; + if (system(cmd.c_str())) + fatal(cmd + " in d1"); + if (chdir("../d2")) + fatal("chdir ../d2"); + if (close(open(tfn1, O_RDWR|O_CREAT, 0755))) + fatal("create d2/tpxattr.txt"); + if (close(open(tfn2, O_RDWR|O_CREAT, 0755))) + fatal("create d2/tpxattr.txt"); + cmd = string("pxattr -S ../d1/" ) + dump; + if (system(cmd.c_str())) + fatal(cmd); + cmd = string("pxattr -lR . > " ) + dump; + if (system(cmd.c_str())) + fatal(cmd + " in d2"); + cmd = string("diff ../d1/") + dump + " " + dump; + if (system(cmd.c_str())) + fatal(cmd); + cmd = string("cat ") + dump; + system(cmd.c_str()); + + if (1) { + unlink(dump); + unlink(tfn1); + unlink(tfn2); + if (chdir("../d1")) + fatal("chdir ../d1"); + unlink(dump); + unlink(tfn1); + unlink(tfn2); + if (chdir("../")) + fatal("chdir .. 1"); + if (rmdir(d1)) + fatal("rmdir d1"); + if (rmdir(d2)) + fatal("rmdir d2"); + if (chdir("../")) + fatal("chdir .. 2"); + if (rmdir(top)) + fatal("rmdir ttop"); + } + return true; +} + +static void dotests() +{ + static const char *tfn = "pxattr_testtmp.xyz"; + static const char *NAMES[] = {"ORG.PXATTR.NAME1", "ORG.PXATTR.N2", + "ORG.PXATTR.LONGGGGGGGGisSSSHHHHHHHHHNAME3"}; + static const char *VALUES[] = {"VALUE1", "VALUE2", "VALUE3"}; + static bool verbose = true; + + /* Create test file if it doesn't exist, remove all attributes */ + int fd = open(tfn, O_RDWR|O_CREAT, 0755); + if (fd < 0) { + perror("open/create"); + exit(1); + } + + if (verbose) + fprintf(stdout, "Cleanup old attrs\n"); + vector names; + if (!pxattr::list(tfn, &names)) { + perror("pxattr::list"); + exit(1); + } + for (vector::const_iterator it = names.begin(); + it != names.end(); it++) { + string value; + if (!pxattr::del(fd, *it)) { + perror("pxattr::del"); + exit(1); + } + } + /* Check that there are no attributes left */ + names.clear(); + if (!pxattr::list(tfn, &names)) { + perror("pxattr::list"); + exit(1); + } + if (names.size() != 0) { + fprintf(stderr, "Attributes remain after initial cleanup !\n"); + for (vector::const_iterator it = names.begin(); + it != names.end(); it++) { + fprintf(stderr, "%s\n", (*it).c_str()); + } + exit(1); + } + + /* Create attributes, check existence and value */ + if (verbose) + fprintf(stdout, "Creating extended attributes\n"); + for (int i = 0; i < 3; i++) { + if (!pxattr::set(fd, NAMES[i], VALUES[i])) { + perror("pxattr::set"); + exit(1); + } + } + if (verbose) + fprintf(stdout, "Checking creation\n"); + for (int i = 0; i < 3; i++) { + string value; + if (!pxattr::get(tfn, NAMES[i], &value)) { + perror("pxattr::get"); + exit(1); + } + if (value.compare(VALUES[i])) { + fprintf(stderr, "Wrong value after create !\n"); + exit(1); + } + } + + /* Delete one, check list */ + if (verbose) + fprintf(stdout, "Delete one\n"); + if (!pxattr::del(tfn, NAMES[1])) { + perror("pxattr::del one name"); + exit(1); + } + if (verbose) + fprintf(stdout, "Check list\n"); + for (int i = 0; i < 3; i++) { + string value; + if (!pxattr::get(fd, NAMES[i], &value)) { + if (i == 1) + continue; + perror("pxattr::get"); + exit(1); + } else if (i == 1) { + fprintf(stderr, "Name at index 1 still exists after deletion\n"); + exit(1); + } + if (value.compare(VALUES[i])) { + fprintf(stderr, "Wrong value after delete 1 !\n"); + exit(1); + } + } + + /* Test the CREATE/REPLACE flags */ + // Set existing with flag CREATE should fail + if (verbose) + fprintf(stdout, "Testing CREATE/REPLACE flags use\n"); + if (pxattr::set(tfn, NAMES[0], VALUES[0], pxattr::PXATTR_CREATE)) { + fprintf(stderr, "Create existing with flag CREATE succeeded !\n"); + exit(1); + } + // Set new with flag REPLACE should fail + if (pxattr::set(tfn, NAMES[1], VALUES[1], pxattr::PXATTR_REPLACE)) { + fprintf(stderr, "Create new with flag REPLACE succeeded !\n"); + exit(1); + } + // Set new with flag CREATE should succeed + if (!pxattr::set(fd, NAMES[1], VALUES[1], pxattr::PXATTR_CREATE)) { + fprintf(stderr, "Create new with flag CREATE failed !\n"); + exit(1); + } + // Set existing with flag REPLACE should succeed + if (!pxattr::set(fd, NAMES[0], VALUES[0], pxattr::PXATTR_REPLACE)) { + fprintf(stderr, "Create existing with flag REPLACE failed !\n"); + exit(1); + } + close(fd); + unlink(tfn); + + if (testbackups()) + exit(0); + exit(1); +} #endif // Testing pxattr #endif // Supported systems.