# HG changeset patch # User Olaf Wintermann # Date 1568747163 -7200 # Node ID 5b8643cf0a2ffbd762a7add16daab09736874d9d # Parent 4e23087d3d90e4feddaa56df582afc2646696071 implement hash push strategy and add some tests diff -r 4e23087d3d90 -r 5b8643cf0a2f dav/sync.c --- a/dav/sync.c Mon Sep 16 19:49:04 2019 +0200 +++ b/dav/sync.c Tue Sep 17 21:06:03 2019 +0200 @@ -2702,6 +2702,10 @@ } } + if(!res->isdirectory && dir->push_strategy == PUSH_STRATEGY_HASH) { + res->hash = util_file_hash(file_path); + } + free(file_path); if(skip_file) { diff -r 4e23087d3d90 -r 5b8643cf0a2f test/bin-test/dav-home/sync.xml --- a/test/bin-test/dav-home/sync.xml Mon Sep 16 19:49:04 2019 +0200 +++ b/test/bin-test/dav-home/sync.xml Tue Sep 17 21:06:03 2019 +0200 @@ -43,4 +43,28 @@ dav-sync-tests-test2b-db.xml true + + + + test2ah + $HOME/tmp-sync/test2a + dav-test-repo + /sync/test2 + .trash + dav-sync-tests-test2a-db.xml + true + hash + + + + test2bh + + $HOME/tmp-sync/test2b + dav-test-repo + /sync/test2 + .trash + dav-sync-tests-test2b-db.xml + true + hash + diff -r 4e23087d3d90 -r 5b8643cf0a2f test/bin-test/test-dav-sync-hash-strategy.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bin-test/test-dav-sync-hash-strategy.sh Tue Sep 17 21:06:03 2019 +0200 @@ -0,0 +1,164 @@ +#!/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 + +# 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 +} + +# 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-test2a-db.xml +rm -f .dav/dav-sync-tests-test2b-db.xml + +$DAV_BIN rm dav-test-repo/sync/test2 2> /dev/null + +$DAV_BIN mkcol dav-test-repo/sync/test2 2> /dev/null + +# tmp sync dir +rm -Rf tmp-sync +mkdir tmp-sync +mkdir tmp-sync/test2a +mkdir tmp-sync/test2b + +# ---------------------------------------------------------------------------- +# test 1: add 4 files, push, pull (not really an hashing test) +# expected result: 4 files pushed, 4 files pulled +# same as hashing test 1 + +mkdir tmp-sync/test2a/dir1/ +mkdir tmp-sync/test2a/dir1/subdir1/ + +cp synctest/file1 tmp-sync/test2a/ +cp synctest/file2 tmp-sync/test2a/dir1/ +cp synctest/file3 tmp-sync/test2a/dir1/subdir1 +cp synctest/file4 tmp-sync/test2a/dir1/subdir1 + +touch -t 01011205 tmp-sync/test2a/file1 +touch -t 01021204 tmp-sync/test2a/dir1/file2 +touch -t 01031203 tmp-sync/test2a/dir1/subdir1/file3 +touch -t 01041202 tmp-sync/test2a/dir1/subdir1/file4 + +dav_sync_push test2ah "test 1: push failed" +check_tmpout "4 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)" + +dav_sync_pull test2bh "test 1: pull failed" +check_tmpout "4 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: change content of two files, don't change mtime +# expected result: 2 files pushed + +echo "test2-change1-f1" >> tmp-sync/test2a/file1 +echo "test2-change1-f2" >> tmp-sync/test2a/dir1/file2 + +touch -t 01011205 tmp-sync/test2a/file1 +touch -t 01021204 tmp-sync/test2a/dir1/file2 + +dav_sync_push test2ah "test 2: push failed" +check_tmpout "2 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)" + +dav_sync_pull test2bh "test 2: pull failed" +check_tmpout "2 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)" + + +# ---------------------------------------------------------------------------- +# test 3: touch file3, change file4 +# expected result: only file4 pushed + +touch tmp-sync/test2a/dir1/subdir1/file3 +echo "test3-change1-f4" >> tmp-sync/test2a/dir1/subdir1/file4 + +dav_sync_push test2ah "test 3: push failed" +check_tmpout "1 file 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 "file4" "test 3: file 4 not pushed" + +dav_sync_pull test2bh "test 3: pull failed" +check_tmpout "1 file 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)" + +diff tmp-sync/test2a/dir1/subdir1/file4 tmp-sync/test2b/dir1/subdir1/file4 > /dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "test 4: file4 not equal" + exit 2 +fi diff -r 4e23087d3d90 -r 5b8643cf0a2f test/bin-test/test-dav-sync-pull-conflict.sh --- a/test/bin-test/test-dav-sync-pull-conflict.sh Mon Sep 16 19:49:04 2019 +0200 +++ b/test/bin-test/test-dav-sync-pull-conflict.sh Tue Sep 17 21:06:03 2019 +0200 @@ -282,7 +282,7 @@ exit 2 fi -TEST7=`dav-sync list-conflicts test1b | wc -l` +TEST7=`$DAV_SYNC_BIN list-conflicts test1b | wc -l` if [ $TEST7 != "0" ]; then echo "test 7: list-conflicts must not show conflicts" return 2 @@ -335,7 +335,7 @@ exit 2 fi -TEST7=`dav-sync list-conflicts test1b | wc -l` +TEST7=`$DAV_SYNC_BIN list-conflicts test1b | wc -l` if [ $TEST7 != "0" ]; then echo "test 8: list-conflicts must not show conflicts" return 2 diff -r 4e23087d3d90 -r 5b8643cf0a2f test/bin-test/test-dav-sync.sh --- a/test/bin-test/test-dav-sync.sh Mon Sep 16 19:49:04 2019 +0200 +++ b/test/bin-test/test-dav-sync.sh Tue Sep 17 21:06:03 2019 +0200 @@ -98,6 +98,7 @@ do_test "dav-sync pull conflict (1)" test-dav-sync-pull-conflict.sh do_test "dav-sync push conflict (1)" test-dav-sync-push-conflict.sh do_test "dav-sync hashing" test-dav-sync-hashing.sh +do_test "dav-sync hash strategy" test-dav-sync-hash-strategy.sh # cleanup $DAV_BIN rm dav-test-repo/sync/test1 > /dev/null 2>&1