get recoll non-gui parts to build under cygwin

This commit is contained in:
medoc 2013-07-15 22:35:04 +02:00
parent dda0937fd1
commit b25f2a37e5
5 changed files with 385 additions and 159 deletions

150
src/configure vendored
View File

@ -1,6 +1,6 @@
#! /bin/sh #! /bin/sh
# Guess values for system-dependent variables and create Makefiles. # 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. # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@ -577,8 +577,8 @@ MAKEFLAGS=
# Identity of this package. # Identity of this package.
PACKAGE_NAME='Recoll' PACKAGE_NAME='Recoll'
PACKAGE_TARNAME='recoll' PACKAGE_TARNAME='recoll'
PACKAGE_VERSION='1.19.0' PACKAGE_VERSION='1.19.5'
PACKAGE_STRING='Recoll 1.19.0' PACKAGE_STRING='Recoll 1.19.5'
PACKAGE_BUGREPORT='' PACKAGE_BUGREPORT=''
PACKAGE_URL='' PACKAGE_URL=''
@ -652,7 +652,9 @@ X_CFLAGS
CXXCPP CXXCPP
XMKMF XMKMF
QMAKEPATH QMAKEPATH
XAPIAN_CONFIG XAPIAN_CONFIG2
XAPIAN_CONFIG1
XAPIAN_CONFIG0
aspellProg aspellProg
fileProg fileProg
EGREP EGREP
@ -1279,7 +1281,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing. # 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. # This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF 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]... Usage: $0 [OPTION]... [VAR=VALUE]...
@ -1344,7 +1346,7 @@ fi
if test -n "$ac_init_help"; then if test -n "$ac_init_help"; then
case $ac_init_help in case $ac_init_help in
short | recursive ) echo "Configuration of Recoll 1.19.0:";; short | recursive ) echo "Configuration of Recoll 1.19.5:";;
esac esac
cat <<\_ACEOF cat <<\_ACEOF
@ -1473,7 +1475,7 @@ fi
test -n "$ac_init_help" && exit $ac_status test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then if $ac_init_version; then
cat <<\_ACEOF cat <<\_ACEOF
Recoll configure 1.19.0 Recoll configure 1.19.5
generated by GNU Autoconf 2.69 generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc. Copyright (C) 2012 Free Software Foundation, Inc.
@ -2026,7 +2028,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake. 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 generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@ $ $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 as_fn_error $? "C++ compiler needed. Please install one (ie: gnu g++)" "$LINENO" 5
fi fi
sys=`uname | tr / _` sys=`uname | tr / _ | awk -F_ '{print $1}'`
if test ! -f mk/$sys ; then if test ! -f mk/$sys ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: { $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 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
LIBICONV="" LIBICONV=""
S_LDFLAGS=$LDFLAGS S_LIBS=$LIBS
S_CPPFLAGS=$CPPFLAGS 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" CPPFLAGS="$S_CPPFLAGS -I$dir/../include"
LDFLAGS="$S_LDFLAGS -L$dir" LIBS="$S_LIBS -L$dir"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
@ -4482,7 +4484,7 @@ rm -f core conftest.err conftest.$ac_objext \
break break
fi fi
LDFLAGS="$S_LDFLAGS -L$dir -liconv" LIBS="$S_LIBS -L$dir -liconv"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
#include <stdlib.h> #include <stdlib.h>
@ -4508,7 +4510,7 @@ rm -f core conftest.err conftest.$ac_objext \
done done
LDFLAGS=$S_LDFLAGS LIBS=$S_LIBS
CPPFLAGS=$S_CPPFLAGS CPPFLAGS=$S_CPPFLAGS
if test A"$LIBICONV" = A ; then if test A"$LIBICONV" = A ; then
@ -4581,17 +4583,20 @@ $as_echo "#define PUTENV_ARG_CONST 1" >>confdefs.h
fi fi
#### Look for Xapian #### Look for Xapian. Done in a strange way to work around autoconf
# Extract the first word of "xapian-config", so it can be a program name with args. # 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 set dummy xapian-config; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; } $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 $as_echo_n "(cached) " >&6
else 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 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@ -4601,7 +4606,7 @@ do
test -z "$as_dir" && as_dir=. test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then 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 $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2 break 2
fi fi
@ -4609,20 +4614,111 @@ done
done done
IFS=$as_save_IFS 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 esac
fi fi
XAPIAN_CONFIG=$ac_cv_path_XAPIAN_CONFIG XAPIAN_CONFIG0=$ac_cv_path_XAPIAN_CONFIG0
if test -n "$XAPIAN_CONFIG"; then if test -n "$XAPIAN_CONFIG0"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $XAPIAN_CONFIG" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XAPIAN_CONFIG0" >&5
$as_echo "$XAPIAN_CONFIG" >&6; } $as_echo "$XAPIAN_CONFIG0" >&6; }
else else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; } $as_echo "no" >&6; }
fi 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 if test "$XAPIAN_CONFIG" = "no" ; then
as_fn_error $? "Cannot find xapian-config command in $PATH. Is as_fn_error $? "Cannot find xapian-config command in $PATH. Is
xapian-core installed ?" "$LINENO" 5 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 # report actual input values of CONFIG_FILES etc. instead of their
# values after options handling. # values after options handling.
ac_log=" 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 generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES CONFIG_FILES = $CONFIG_FILES
@ -6321,7 +6417,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\ ac_cs_version="\\
Recoll config.status 1.19.0 Recoll config.status 1.19.5
configured by $0, generated by GNU Autoconf 2.69, configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\" with options \\"\$ac_cs_config\\"

View File

@ -8,7 +8,7 @@ if test C$CXX = C ; then
AC_MSG_ERROR([C++ compiler needed. Please install one (ie: gnu g++)]) AC_MSG_ERROR([C++ compiler needed. Please install one (ie: gnu g++)])
fi fi
sys=`uname | tr / _` sys=`uname | tr / _ | awk -F_ '{print $1}'`
if test ! -f mk/$sys ; then if test ! -f mk/$sys ; then
AC_MSG_NOTICE([ AC_MSG_NOTICE([
@ -251,12 +251,12 @@ AC_CHECK_FUNCS(mkdtemp)
##### libiconv. We'd need a --with-libiconv= option ##### libiconv. We'd need a --with-libiconv= option
AC_LANG(C++) AC_LANG(C++)
LIBICONV="" LIBICONV=""
S_LDFLAGS=$LDFLAGS S_LIBS=$LIBS
S_CPPFLAGS=$CPPFLAGS 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" CPPFLAGS="$S_CPPFLAGS -I$dir/../include"
LDFLAGS="$S_LDFLAGS -L$dir" LIBS="$S_LIBS -L$dir"
AC_TRY_LINK([#include <stdlib.h> AC_TRY_LINK([#include <stdlib.h>
#include <iconv.h>], #include <iconv.h>],
[iconv_t cd = iconv_open("",""); [iconv_t cd = iconv_open("","");
@ -267,7 +267,7 @@ for dir in ${libdir} /opt/local/lib /usr/local/lib ;do
break break
fi fi
LDFLAGS="$S_LDFLAGS -L$dir -liconv" LIBS="$S_LIBS -L$dir -liconv"
AC_TRY_LINK([#include <stdlib.h> AC_TRY_LINK([#include <stdlib.h>
#include <iconv.h>], #include <iconv.h>],
[iconv_t cd = iconv_open("",""); [iconv_t cd = iconv_open("","");
@ -280,7 +280,7 @@ for dir in ${libdir} /opt/local/lib /usr/local/lib ;do
done done
LDFLAGS=$S_LDFLAGS LIBS=$S_LIBS
CPPFLAGS=$S_CPPFLAGS CPPFLAGS=$S_CPPFLAGS
if test A"$LIBICONV" = A ; then if test A"$LIBICONV" = A ; then
@ -315,8 +315,22 @@ if test X$rcl_putenv_string_const = X1 ; then
fi fi
#### Look for Xapian #### Look for Xapian. Done in a strange way to work around autoconf
AC_PATH_PROG(XAPIAN_CONFIG, xapian-config, no) # 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 if test "$XAPIAN_CONFIG" = "no" ; then
AC_MSG_ERROR([Cannot find xapian-config command in $PATH. Is AC_MSG_ERROR([Cannot find xapian-config command in $PATH. Is
xapian-core installed ?]) xapian-core installed ?])

View File

@ -4,7 +4,7 @@ include $(depth)/mk/sysconf
LIBRECOLL=librecoll.so.$(RCLLIBVERSION) LIBRECOLL=librecoll.so.$(RCLLIBVERSION)
LIBS = librecoll.a LIBS = librecoll.a
LIBS = librecoll.a $(LIBRECOLL) #LIBS = librecoll.a $(LIBRECOLL)
all: $(LIBS) all: $(LIBS)

10
src/mk/CYGWIN Normal file
View File

@ -0,0 +1,10 @@
include $(depth)/mk/commondefs
include $(depth)/mk/localdefs
ALL_CXXFLAGS = $(CXXFLAGS) $(COMMONCXXFLAGS) $(LOCALCXXFLAGS) \
-D_GNU_SOURCE
LIBSYS = -lpthread -ldl
LIBSYSTHREADS =

View File

@ -23,9 +23,14 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE. 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 // We want this to compile even to empty on non-supported systems. makes
// things easier for autoconf // 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 #ifndef TEST_PXATTR
@ -39,6 +44,8 @@ OTHER DEALINGS IN THE SOFTWARE.
#include <sys/uio.h> #include <sys/uio.h>
#elif defined(__gnu_linux__) #elif defined(__gnu_linux__)
#include <sys/xattr.h> #include <sys/xattr.h>
#elif defined(__CYGWIN32__)
#include <sys/xattr.h>
#elif defined(__APPLE__) #elif defined(__APPLE__)
#include <sys/xattr.h> #include <sys/xattr.h>
#else #else
@ -489,128 +496,7 @@ using namespace std;
#include "pxattr.h" #include "pxattr.h"
static void dotests() 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<string> names;
if (!pxattr::list(tfn, &names)) {
perror("pxattr::list");
exit(1);
}
for (vector<string>::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<string>::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);
}
// \-quote character c in input \ -> \\, nl -> \n cr -> \rc -> \c // \-quote character c in input \ -> \\, nl -> \n cr -> \rc -> \c
static void quote(const string& in, string& out, int c) static void quote(const string& in, string& out, int c)
@ -938,7 +824,227 @@ int main(int argc, char **argv)
exit(0); 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<string> names;
if (!pxattr::list(tfn, &names)) {
perror("pxattr::list");
exit(1);
}
for (vector<string>::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<string>::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 // Testing pxattr
#endif // Supported systems. #endif // Supported systems.