Sat, 23 Nov 2019 17:49:18 +0100
add symlink tests
--- a/dav/sync.c Sat Nov 23 15:14:50 2019 +0100 +++ b/dav/sync.c Sat Nov 23 17:49:18 2019 +0100 @@ -1040,7 +1040,7 @@ ret = type; } } else if(link) { - if(type == REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED) { + if(exists && type == REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED) { ret = REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED; } else { ret = REMOTE_CHANGE_LINK;
--- a/test/bin-test/dav-home/sync.xml Sat Nov 23 15:14:50 2019 +0100 +++ b/test/bin-test/dav-home/sync.xml Sat Nov 23 17:49:18 2019 +0100 @@ -251,4 +251,53 @@ </split> </splitconfig> </directory> + + <!-- + Test 7: symlinks + --> + <directory> + <name>test7a</name> + <path>$HOME/tmp-sync/test7a</path> + <repository>dav-test-repo</repository> + <collection>/sync/test7</collection> + <trash>.trash</trash> + <database>dav-sync-tests-test7a-db.xml</database> + + <symlink-intern>sync</symlink-intern> + </directory> + + <directory> + <name>test7b</name> + <path>$HOME/tmp-sync/test7b</path> + <repository>dav-test-repo</repository> + <collection>/sync/test7</collection> + <trash>.trash</trash> + <database>dav-sync-tests-test7b-db.xml</database> + + <symlink-intern>sync</symlink-intern> + </directory> + + <directory> + <name>test7a1</name> <!-- same dir/db as test7a --> + <path>$HOME/tmp-sync/test7a</path> + <repository>dav-test-repo</repository> + <collection>/sync/test7</collection> + <trash>.trash</trash> + <database>dav-sync-tests-test7a-db.xml</database> + + <symlink-intern>ignore</symlink-intern> + <symlink-extern>ignore</symlink-extern> + </directory> + + <directory> + <name>test7a2</name> <!-- same dir/db as test7a --> + <path>$HOME/tmp-sync/test7a</path> + <repository>dav-test-repo</repository> + <collection>/sync/test7</collection> + <trash>.trash</trash> + <database>dav-sync-tests-test7a-db.xml</database> + + <symlink-intern>sync</symlink-intern> + <symlink-extern>ignore</symlink-extern> + </directory> </configuration>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bin-test/test-dav-sync-symlink1.sh Sat Nov 23 17:49:18 2019 +0100 @@ -0,0 +1,267 @@ +#!/bin/sh +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2019 Olaf Wintermann. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +if [ -z "$DAV_BIN" ]; +then + echo "DAV_BIN variable not set" + exit 1 +fi +if [ -z "$DAV_SYNC_BIN" ]; +then + echo "DAV_BIN variable not set" + exit 1 +fi + +XATTR=../../build/xattrtool + +# checks if tmp-sync/out.txt contains a specific text +# arg1: pattern +# arg2: errormsg +check_tmpout() +{ + TEST=`cat tmp-sync/out.txt | grep "$1"` + if [ $? -ne 0 ]; + then + echo "$2" + exit 2 + fi +} + +# checks if tmp-sync/out.txt does not contain a specific text +# arg1: pattern +# arg2: errormsg +ncheck_tmpout() +{ + TEST=`cat tmp-sync/out.txt | grep "$1"` + if [ $? -eq 0 ]; + then + echo "$2" + exit 2 + fi +} + +# do dav-sync push and check return value +# arg1: dir +# arg2: errormsg +dav_sync_push() +{ + $DAV_SYNC_BIN push $1 > tmp-sync/out.txt + if [ $? -ne 0 ]; + then + echo "$2" + exit 2 + fi +} +# do dav-sync pull and check return value +# arg1: dir +# arg2: errormsg +dav_sync_pull() +{ + $DAV_SYNC_BIN pull $1 > tmp-sync/out.txt + if [ $? -ne 0 ]; + then + echo "$2" + exit 2 + fi +} + +rm -f .dav/dav-sync-tests-test7a-db.xml +rm -f .dav/dav-sync-tests-test7b-db.xml + +$DAV_BIN rm dav-test-repo/sync/test7 2> /dev/null + +$DAV_BIN mkcol dav-test-repo/sync/test7 2> /dev/null + +# tmp sync dir +rm -Rf tmp-sync +mkdir tmp-sync +mkdir tmp-sync/test7a +mkdir tmp-sync/test7b + +# ---------------------------------------------------------------------------- +# test 1: try to sync symlinks with symlinks disabled (test7a1) +# expected result: only normal files synced + +mkdir tmp-sync/files +mkdir tmp-sync/test7a/dir1 +mkdir tmp-sync/test7a/dir1/sub1 + +echo "extern-file1" > tmp-sync/extern1 +echo "extern-file2" > tmp-sync/files/extern2 +echo "extern-file3" > tmp-sync/files/extern3 + +which ln > /dev/null 2>&1 +if [ $? -ne 0 ]; then + exit 0 # symlinks unsupported on this platform +fi + +ln -s -r tmp-sync/extern1 tmp-sync/test7a/extern1 > /dev/null 2>&1 +if [ $? -ne 0 ]; then + exit 0 # symlinks unsupported on this platform +fi + +ln -s -r tmp-sync/files/extern2 tmp-sync/test7a/extern2 +ln -s -r tmp-sync/files/extern3 tmp-sync/test7a/dir1/sub1/extern3 + +cp synctest/file1 tmp-sync/test7a +cp synctest/file2 tmp-sync/test7a/dir1 +cp synctest/file3 tmp-sync/test7a/dir1/sub1 + +ln -s -r tmp-sync/test7a/file1 tmp-sync/test7a/intern1 +ln -s -r tmp-sync/test7a/dir1/file2 tmp-sync/test7a/intern2 +ln -s -r tmp-sync/test7a/file1 tmp-sync/test7a/dir1/sub1/intern3 + +dav_sync_push test7a1 "test 1: push failed" +check_tmpout "3 files pushed" "test 1: wrong push counter" +check_tmpout "0 conflicts" "test 1: wrong conflict counter (push)" +check_tmpout "0 errors" "test 1: wrong error counter (push)" +ncheck_tmpout "extern" "test 1: external symlinks pushed" +ncheck_tmpout "intern" "test 1: internal symlinks pushed" + +dav_sync_pull test7b "test 1: pull failed" +check_tmpout "3 files pulled" "test 1: wrong pull counter" +check_tmpout "0 conflicts" "test 1: wrong conflict counter (pull)" +check_tmpout "0 errors" "test 1: wrong error counter (pull)" + + +# ---------------------------------------------------------------------------- +# test 2: try to sync internal symlinks (test7a2) +# expected result: internal symlinks synced, external symlinks ignored + +dav_sync_push test7a2 "test 2: push failed" +check_tmpout "3 files pushed" "test 2: wrong push counter" +check_tmpout "0 conflicts" "test 2: wrong conflict counter (push)" +check_tmpout "0 errors" "test 2: wrong error counter (push)" +check_tmpout "link: /intern1" "test 2: no links created (push)" +ncheck_tmpout "extern" "test 2: external symlinks pushed" + +dav_sync_pull test7b "test 2: pull failed" +check_tmpout "3 files pulled" "test 2: wrong pull counter" +check_tmpout "0 conflicts" "test 2: wrong conflict counter (pull)" +check_tmpout "0 errors" "test 2: wrong error counter (pull)" +check_tmpout "link: /intern1" "test 2: no links created (pull)" + +# compare links +HASH_A=`cat tmp-sync/test7a/intern1 | sha256sum` +HASH_B=`cat tmp-sync/test7b/intern1 | sha256sum` +if [ "$HASH_A" != "$HASH_B" ]; then + echo "test 2: intern1 has wrong content" + exit 2 +fi +HASH_A=`cat tmp-sync/test7a/intern2 | sha256sum` +HASH_B=`cat tmp-sync/test7b/intern2 | sha256sum` +if [ "$HASH_A" != "$HASH_B" ]; then + echo "test 2: intern2 has wrong content" + exit 2 +fi +HASH_A=`cat tmp-sync/test7a/dir1/sub1/intern3 | sha256sum` +HASH_B=`cat tmp-sync/test7b/dir1/sub1/intern3 | sha256sum` +if [ "$HASH_A" != "$HASH_B" ]; then + echo "test 2: intern3 has wrong content" + exit 2 +fi + + +# ---------------------------------------------------------------------------- +# test 3: push with symlink-extern follow (test7a) +# expected result: external links pushed as regular files + +dav_sync_push test7a "test 3: push failed" +check_tmpout "3 files pushed" "test 3: wrong push counter" +check_tmpout "0 conflicts" "test 3: wrong conflict counter (push)" +check_tmpout "0 errors" "test 3: wrong error counter (push)" +check_tmpout "extern" "test 3: no links created (push)" + +dav_sync_pull test7b "test 3: pull failed" +check_tmpout "3 files pulled" "test 3: wrong pull counter" +check_tmpout "0 conflicts" "test 3: wrong conflict counter (pull)" +check_tmpout "0 errors" "test 3: wrong error counter (pull)" + + +# ---------------------------------------------------------------------------- +# test 4: push, add new file, push (test if double sync happens) +# expected result: push1: 0 files pushed, push2: 1 file pushed + +dav_sync_push test7a "test 4: push failed" +check_tmpout "0 files pushed" "test 4: wrong push counter" +check_tmpout "0 conflicts" "test 4: wrong conflict counter (push)" +check_tmpout "0 errors" "test 4: wrong error counter (push)" + +echo "test3-new1" > tmp-sync/test7a/new1 + +dav_sync_push test7a "test 4: push 2 failed" +check_tmpout "1 file pushed" "test 4: wrong push counter (2)" +check_tmpout "0 conflicts" "test 4: wrong conflict counter (2)" +check_tmpout "0 errors" "test 4: wrong error counter (2)" + +dav_sync_pull test7b "test 4: pull failed" +check_tmpout "1 file pulled" "test 4: wrong pull counter" +check_tmpout "0 conflicts" "test 4: wrong conflict counter (pull)" +check_tmpout "0 errors" "test 4: wrong error counter (pull)" + + +# ---------------------------------------------------------------------------- +# test 5: modify file1, sync +# expected result: file1 synced, intern1 not synced + +sleep 2 + +echo "test5-mod1" >> tmp-sync/test7a/file1 + +dav_sync_push test7a "test 5: push failed" +check_tmpout "1 file pushed" "test 5: wrong push counter" +check_tmpout "0 conflicts" "test 5: wrong conflict counter (push)" +check_tmpout "0 errors" "test 5: wrong error counter (push)" +ncheck_tmpout "intern1" "test 5: intern1 updated (push)" + +dav_sync_pull test7b "test 5: pull failed" +check_tmpout "1 file pulled" "test 5: wrong pull counter" +check_tmpout "0 conflicts" "test 5: wrong conflict counter (pull)" +check_tmpout "0 errors" "test 5: wrong error counter (pull)" + + +# ---------------------------------------------------------------------------- +# test 6: change intern1 target +# expected result: intern1 updated + +rm -f tmp-sync/test7a/intern1 +ln -s -r tmp-sync/test7a/new1 tmp-sync/test7a/intern1 + +dav_sync_push test7a "test 6: push failed" +check_tmpout "1 file pushed" "test 6: wrong push counter" +check_tmpout "0 conflicts" "test 6: wrong conflict counter (push)" +check_tmpout "0 errors" "test 6: wrong error counter (push)" +check_tmpout "intern1" "test 6: intern1 not updated (push)" + +dav_sync_pull test7b "test 6: pull failed" +check_tmpout "1 file pulled" "test 6: wrong pull counter" +check_tmpout "0 conflicts" "test 6: wrong conflict counter (pull)" +check_tmpout "0 errors" "test 6: wrong error counter (pull)" +check_tmpout "intern1" "test 6: intern1 not updated (pull)" +
--- a/test/bin-test/test-dav-sync.sh Sat Nov 23 15:14:50 2019 +0100 +++ b/test/bin-test/test-dav-sync.sh Sat Nov 23 17:49:18 2019 +0100 @@ -107,6 +107,7 @@ do_test "dav-sync metadata (4)" test-dav-sync-metadata4.sh do_test "dav-sync versioning (1)" test-dav-sync-versioning1.sh do_test "dav-sync split (1)" test-dav-sync-split1.sh +do_test "dav-sync symlink (1)" test-dav-sync-symlink1.sh # cleanup $DAV_BIN rm dav-test-repo/sync/test1 > /dev/null 2>&1