fix some hash based conflict resolution bugs and add tests for it

Sun, 06 Oct 2019 13:27:24 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 06 Oct 2019 13:27:24 +0200
changeset 650
14e7101d7604
parent 649
0f4c59ac8c74
child 651
6d1d569068bf

fix some hash based conflict resolution bugs and add tests for it

dav/sync.c file | annotate | diff | comparison | revisions
test/bin-test/test-dav-sync-hash-conflictres.sh file | annotate | diff | comparison | revisions
test/bin-test/test-dav-sync-hashing.sh file | annotate | diff | comparison | revisions
test/bin-test/test-dav-sync-hashing1.sh file | annotate | diff | comparison | revisions
test/bin-test/test-dav-sync-hashing2.sh file | annotate | diff | comparison | revisions
test/bin-test/test-dav-sync.sh file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Thu Oct 03 12:00:25 2019 +0200
+++ b/dav/sync.c	Sun Oct 06 13:27:24 2019 +0200
@@ -1039,6 +1039,8 @@
      
     // if hashing is enabled we can compare the hash of the remote file
     // with the local file to test if a file is really modified
+    DavBool update_db = FALSE;
+    char *update_hash = NULL;
     if (!iscollection &&
         !link &&
         (ret == REMOTE_CHANGE_MODIFIED || ret == REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED) &&
@@ -1052,9 +1054,23 @@
         if(local_hash) {
             if(!strcmp(hash, local_hash)) {
                 ret = REMOTE_NO_CHANGE;
+                update_db = TRUE;
+                update_hash = local_hash;
+                
+                // if local already exists, update the hash here
+                // because it is possible that there are metadata updates
+                // and in this case the db will updated later and needs
+                // the current hash
+                if(local) {
+                    if(local->hash) {
+                        free(local->hash);
+                    }
+                    local->hash = local_hash;
+                }
+            } else {
+                free(local_hash);
             }
         }
-        free(local_hash);
     }
     
     // if a file is not modified, check if the metadata has changed
@@ -1104,6 +1120,29 @@
         break;
     }
     
+    // if update_db is set, a file was modified on the server, but we already
+    // have the file content, but we need to update the db
+    if(ret == REMOTE_NO_CHANGE && update_db) {
+        if(!local) {
+            local = calloc(1, sizeof(LocalResource));
+            local->path = strdup(res->path);
+            
+            ucx_map_cstr_put(db->resources, local->path, local);
+        }
+        
+        // update local res
+        SYS_STAT s;
+        if(!sys_stat(local_path, &s)) {
+            sync_set_metadata_from_stat(local, &s);
+        } else {
+            fprintf(stderr, "stat failed for file: %s : %s", local_path, strerror(errno));
+        }
+        local_resource_set_etag(local, etag);
+        if(!local->hash) {
+            local->hash = update_hash;
+        } // else: hash already updated
+    }
+        
     free(local_path);
     return ret;
 }
@@ -2151,8 +2190,15 @@
             DavBool equal = FALSE;
             int changed = remote_resource_is_changed(sn, dir, db, res, local_res, &equal);
             if(equal) {
+                char *etag = dav_get_string_property(res, "D:getetag");
                 if(local_res->metadata_updated) {
                     ls_update = ucx_list_prepend(ls_update, local_res);
+                } else if(etag) {
+                    // update etag in db
+                    if(local_res->etag) {
+                        free(local_res->etag);
+                    }
+                    local_res->etag = strdup(etag);
                 }
             } else if(cdt && changed) {
                 printf("conflict: %s\n", local_res->path);
@@ -2256,9 +2302,6 @@
         remove(locktokenfile);
     }
     
-    //ucx_map_free_content(db->resources, (ucx_destructor)local_resource_free);
-    //ucx_map_free(db->resources);
-    
     dav_session_destroy(sn);
     
     // Report
@@ -2866,15 +2909,14 @@
             {
                 // mtime and size unchanged, content also likely unchanged
                 return 0;
-            } else if(SYNC_HASHING(dir) && db_res->hash) {
-                // in case of activated hashing, we check if the content
-                // has really changed
-                
+            } else if(SYNC_HASHING(dir)) {
                 // res->hash missing (see above)
                 char *local_path = util_concat_path(dir->path, local_resource_path(res));
                 res->hash = util_file_hash(local_path);
                 free(local_path);
-                if(res->hash && !strcmp(res->hash, db_res->hash)) {
+                
+                // check if the content has really changed
+                if(res->hash && db_res->hash && !strcmp(res->hash, db_res->hash)) {
                     return 0;
                 }
             }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bin-test/test-dav-sync-hash-conflictres.sh	Sun Oct 06 13:27:24 2019 +0200
@@ -0,0 +1,422 @@
+#!/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
+# don't create test2b
+
+# ----------------------------------------------------------------------------
+# test 1: first pull with exiting files
+# expected result: no conflicts
+
+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
+
+cp -R tmp-sync/test2a tmp-sync/test2b
+
+dav_sync_push test2a "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 test2b "test 1: pull failed"
+check_tmpout "0 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: first push with existing resources on the server
+# expected result: no conflicts
+
+rm -f .dav/dav-sync-tests-test2a-db.xml
+
+sleep 2
+
+dav_sync_push test2a "test 2: push failed"
+check_tmpout "0 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 test2b "test 2: pull failed"
+check_tmpout "0 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: modify file1 on both sides (with same content)
+# expected result: (pull): no conflicts
+
+sleep 2
+
+echo "test3-mod" >> tmp-sync/test2a/file1
+echo "test3-mod" >> tmp-sync/test2b/file1
+
+dav_sync_push test2a "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)"
+
+dav_sync_pull test2b "test 3: pull failed"
+check_tmpout "0 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: modify file2 on both sides (with same content) and push test2b
+# expected result: (push): no conflicts
+
+sleep 2
+
+echo "test4-mod" >> tmp-sync/test2a/dir1/file2
+echo "test4-mod" >> tmp-sync/test2b/dir1/file2
+
+dav_sync_push test2a "test 4: push test2a failed"
+check_tmpout "1 file pushed" "test 4: wrong push counter (test2a)"
+check_tmpout "0 conflicts" "test 4: wrong conflict counter (test2a)"
+check_tmpout "0 errors" "test 4: wrong error counter (test2a)"
+
+dav_sync_push test2b "test 4: push test2b failed"
+check_tmpout "0 files pushed" "test 4: wrong push counter (test2b)"
+check_tmpout "0 conflicts" "test 4: wrong conflict counter (test2b)"
+check_tmpout "0 errors" "test 4: wrong error counter (test2b)"
+
+dav_sync_pull test2b "test 4: pull failed"
+check_tmpout "0 files 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: add same new file on both sides
+# expected result: (pull): no conflicts
+
+echo "test5-newfilex1" >> tmp-sync/test2a/filex1
+echo "test5-newfilex1" >> tmp-sync/test2b/filex1
+
+echo "test5-newfilex2" >> tmp-sync/test2a/filex2
+echo "test5-newfilex2" >> tmp-sync/test2b/filex2
+
+dav_sync_push test2a "test 5: push failed"
+check_tmpout "2 files pushed" "test 5: wrong push counter (push)"
+check_tmpout "0 conflicts" "test 5: wrong conflict counter (push)"
+check_tmpout "0 errors" "test 5: wrong error counter (push)"
+
+dav_sync_pull test2b "test 5: pull failed"
+check_tmpout "0 files 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: add same new file on both sides and try to push both
+# expected result: no conflicts
+
+echo "test5-newfilez1" >> tmp-sync/test2a/filez1
+echo "test5-newfilez1" >> tmp-sync/test2b/filez1
+
+echo "test5-newfilez2" >> tmp-sync/test2a/filez2
+echo "test5-newfilez2" >> tmp-sync/test2b/filez2
+
+dav_sync_push test2a "test 6: push test2a failed"
+check_tmpout "2 files pushed" "test 6: wrong push counter (test2a)"
+check_tmpout "0 conflicts" "test 6: wrong conflict counter (test2a)"
+check_tmpout "0 errors" "test 6: wrong error counter (test2a)"
+
+dav_sync_push test2b "test 6: push test2b failed"
+check_tmpout "0 files pushed" "test 6: wrong push counter (test2b)"
+check_tmpout "0 conflicts" "test 6: wrong conflict counter (test2b)"
+check_tmpout "0 errors" "test 6: wrong error counter (test2b)"
+
+
+# ----------------------------------------------------------------------------
+# test 7: provoke real conflict, push test2a, pull test2b
+# expected result: (pull): conflict
+
+sleep 2
+
+echo "test7-mod-a" >> tmp-sync/test2a/file1
+echo "test7-mod-b" >> tmp-sync/test2b/file1
+
+dav_sync_push test2a "test 7: push failed"
+check_tmpout "1 file pushed" "test 7: wrong push counter (push)"
+check_tmpout "0 conflicts" "test 7: wrong conflict counter (push)"
+check_tmpout "0 errors" "test 7: wrong error counter (push)"
+
+dav_sync_pull test2b "test 7: pull failed"
+check_tmpout "1 file pulled" "test 7: wrong pull counter"
+check_tmpout "1 conflict" "test 7: wrong conflict counter (pull)"
+check_tmpout "0 errors" "test 7: wrong error counter (pull)"
+
+$DAV_SYNC_BIN delete-conflicts test2b > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 7: delete-conflicts failed"
+	exit 2
+fi
+
+dav_sync_push test2b "test 7: push test2b failed"
+check_tmpout "0 files pushed" "test 7: wrong push counter (test2b)"
+check_tmpout "0 conflicts" "test 7: wrong conflict counter (test2b)"
+check_tmpout "0 errors" "test 7: wrong error counter (test2b)"
+
+
+# ----------------------------------------------------------------------------
+# test 8: provoke real conflict, push both
+# expected result: (push): conflict
+
+sleep 2
+
+echo "test8-mod-a" >> tmp-sync/test2a/dir1/file2
+echo "test8-mod-b" >> tmp-sync/test2b/dir1/file2
+
+dav_sync_push test2a "test 8: push test2a failed"
+check_tmpout "1 file pushed" "test 8: wrong push counter (test2a)"
+check_tmpout "0 conflicts" "test 8: wrong conflict counter (test2a)"
+check_tmpout "0 errors" "test 8: wrong error counter (test2a)"
+
+dav_sync_push test2b "test 8: push test2b failed"
+check_tmpout "0 files pushed" "test 8: wrong push counter (test2b)"
+check_tmpout "1 conflict" "test 8: wrong conflict counter (test2b)"
+check_tmpout "0 errors" "test 8: wrong error counter (test2b)"
+
+
+# ----------------------------------------------------------------------------
+# test 9: resolve push conflict by manually syncing file2
+# expected result: (push): no conflict
+
+cp -f tmp-sync/test2a/dir1/file2 tmp-sync/test2b/dir1/file2
+
+dav_sync_push test2b "test 9: push test2b failed"
+check_tmpout "0 files pushed" "test 9: wrong push counter (test2b)"
+check_tmpout "0 conflicts" "test 9: wrong conflict counter (test2b)"
+check_tmpout "0 errors" "test 9: wrong error counter (test2b)"
+
+
+# ----------------------------------------------------------------------------
+# test 10: provoke real conflict, push test2a, pull test2b
+# expected result: (pull): conflict
+
+sleep 2
+
+echo "test10-mod-a" >> tmp-sync/test2a/dir1/file2
+echo "test10-mod-b" >> tmp-sync/test2b/dir1/file2
+
+dav_sync_push test2a "test 10: push test2a failed"
+check_tmpout "1 file pushed" "test 10: wrong push counter (test2a)"
+check_tmpout "0 conflicts" "test 10: wrong conflict counter (test2a)"
+check_tmpout "0 errors" "test 10: wrong error counter (test2a)"
+
+dav_sync_pull test2b "test 10: pull failed"
+check_tmpout "1 file pulled" "test 10: wrong pull counter (pull)"
+check_tmpout "1 conflict" "test 10: wrong conflict counter (pull)"
+check_tmpout "0 errors" "test 10: wrong error counter (pull)"
+
+$DAV_SYNC_BIN delete-conflicts test2b > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 10: delete-conflicts failed"
+	exit 2
+fi
+
+dav_sync_push test2b "test 10: push test2b failed"
+check_tmpout "0 files pushed" "test 10: wrong push counter (test2b)"
+check_tmpout "0 conflicts" "test 10: wrong conflict counter (test2b)"
+check_tmpout "0 errors" "test 10: wrong error counter (test2b)"
+
+
+# ----------------------------------------------------------------------------
+# test 11: If hashes are equal and 0 files are pulled, check if
+#          the db was updated. Modify a file after pull and push the new file
+# expected result: (push): no conflict, 1 file pushed
+
+sleep 2
+
+echo "test11-mod" >> tmp-sync/test2a/file1
+echo "test11-mod" >> tmp-sync/test2b/file1
+
+dav_sync_push test2a "test 11: push test2a failed"
+check_tmpout "1 file pushed" "test 11: wrong push counter (test2a)"
+check_tmpout "0 conflicts" "test 11: wrong conflict counter (test2a)"
+check_tmpout "0 errors" "test 11: wrong error counter (test2a)"
+
+dav_sync_pull test2b "test 11: pull failed"
+check_tmpout "0 files pulled" "test 11: wrong pull counter"
+check_tmpout "0 conflicts" "test 11: wrong conflict counter (pull)"
+check_tmpout "0 errors" "test 11: wrong error counter (pull)"
+
+sleep 2
+echo "test11-mod2-b" >> tmp-sync/test2b/file1
+
+dav_sync_push test2b "test 11: push test2b failed"
+check_tmpout "1 file pushed" "test 11: wrong push counter (test2b)"
+check_tmpout "0 conflicts" "test 11: wrong conflict counter (test2b)"
+check_tmpout "0 errors" "test 11: wrong error counter (test2b)"
+
+
+# ----------------------------------------------------------------------------
+# test 12: same as test 11 but with a new file and not an existing file
+# expected result: (push): no conflict, 1 file pushed
+
+echo "test12-new" >> tmp-sync/test2a/new-t12
+echo "test12-new" >> tmp-sync/test2b/new-t12
+
+dav_sync_push test2a "test 12: push test2a failed"
+check_tmpout "1 file pushed" "test 12: wrong push counter (test2a)"
+check_tmpout "0 conflicts" "test 12: wrong conflict counter (test2a)"
+check_tmpout "0 errors" "test 12: wrong error counter (test2a)"
+
+dav_sync_pull test2b "test 12: pull failed"
+check_tmpout "0 files pulled" "test 12: wrong pull counter"
+check_tmpout "0 conflicts" "test 12: wrong conflict counter (pull)"
+check_tmpout "0 errors" "test 12: wrong error counter (pull)"
+
+sleep 2
+echo "test12-mod2-b" >> tmp-sync/test2b/new-t12
+
+dav_sync_push test2b "test 12: push test2b failed"
+check_tmpout "1 file pushed" "test 12: wrong push counter (test2b)"
+check_tmpout "0 conflicts" "test 12: wrong conflict counter (test2b)"
+check_tmpout "0 errors" "test 12: wrong error counter (test2b)"
+
+# ----------------------------------------------------------------------------
+# test 13: Check if push updates the db, if a modified file is already
+#          updated (hashes equal). Modify file the same way on both sides,
+#          push both, modify file in test2b and push again
+# expected result: (push): no conflict, 1 file pushed
+
+echo "test13-mod" >> tmp-sync/test2a/dir1/file2
+echo "test13-mod" >> tmp-sync/test2b/dir1/file2
+
+dav_sync_push test2a "test 13: push test2a failed"
+check_tmpout "1 file pushed" "test 13: wrong push counter (test2a)"
+check_tmpout "0 conflicts" "test 13: wrong conflict counter (test2a)"
+check_tmpout "0 errors" "test 13: wrong error counter (test2a)"
+
+dav_sync_push test2b "test 13: push test2b failed"
+check_tmpout "0 files pushed" "test 13: wrong push counter (test2b)"
+check_tmpout "0 conflicts" "test 13: wrong conflict counter (test2b)"
+check_tmpout "0 errors" "test 13: wrong error counter (test2b)"
+
+sleep 2
+echo "test13-mod2-b" >> tmp-sync/test2b/dir1/file2
+
+dav_sync_push test2b "test 13: push test2b (2) failed"
+check_tmpout "1 file pushed" "test 13: wrong push counter (test2b 2)"
+check_tmpout "0 conflicts" "test 13: wrong conflict counter (test2b 2)"
+check_tmpout "0 errors" "test 13: wrong error counter (test2b 2)"
+
+
+# ----------------------------------------------------------------------------
+# test 14: same as test 13 but with a new file and not an existing file
+# expected result: (push): no conflict, 1 file pushed
+
+echo "test14-mod" >> tmp-sync/test2a/dir1/new-t14
+echo "test14-mod" >> tmp-sync/test2b/dir1/new-t14
+
+dav_sync_push test2a "test 14: push test2a failed"
+check_tmpout "1 file pushed" "test 14: wrong push counter (test2a)"
+check_tmpout "0 conflicts" "test 14: wrong conflict counter (test2a)"
+check_tmpout "0 errors" "test 14: wrong error counter (test2a)"
+
+dav_sync_push test2b "test 14: push test2b failed"
+check_tmpout "0 files pushed" "test 14: wrong push counter (test2b)"
+check_tmpout "0 conflicts" "test 14: wrong conflict counter (test2b)"
+check_tmpout "0 errors" "test 14: wrong error counter (test2b)"
+
+sleep 2
+echo "test13-mod2-b" >> tmp-sync/test2b/dir1/new-t14
+
+dav_sync_push test2b "test 14: push test2b (2) failed"
+check_tmpout "1 file pushed" "test 14: wrong push counter (test2b 2)"
+check_tmpout "0 conflicts" "test 14: wrong conflict counter (test2b 2)"
+check_tmpout "0 errors" "test 14: wrong error counter (test2b 2)"
--- a/test/bin-test/test-dav-sync-hashing.sh	Thu Oct 03 12:00:25 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,440 +0,0 @@
-#!/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
-
-# ----------------------------------------------------------------------------
-# 1. test: add 4 files, push, pull (not really an hashing test)
-# expected result: 4 files pushed, 4 files pulled
-
-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
-
-dav_sync_push test2a "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 test2b "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)"
-
-
-# ----------------------------------------------------------------------------
-# 2. test: touch 2 files, push
-# expected result: 0 files pushed
-
-sleep 3
-
-touch tmp-sync/test2a/file1
-touch tmp-sync/test2a/dir1/file2
-
-dav_sync_push test2a "test 2: push failed"
-check_tmpout "0 files pushed" "test 2: wrong push counter"
-check_tmpout "0 conflicts" "test 2: wrong conflict counter"
-check_tmpout "0 errors" "test 2: wrong error counter"
-
-
-# ----------------------------------------------------------------------------
-# 3. test: copy fil1 to test2a again
-# expected result: 0 files pushed
-
-sleep 3
-
-cp synctest/file1 tmp-sync/test2a/
-
-dav_sync_push test2a "test 3: push failed"
-check_tmpout "0 files pushed" "test 3: wrong push counter"
-check_tmpout "0 conflicts" "test 3: wrong conflict counter"
-check_tmpout "0 errors" "test 3: wrong error counter"
-
-
-# ----------------------------------------------------------------------------
-# 4. test: change content but don't change mtime
-# expected result: 1 file pushed
-
-# modify file and mtime to update mtime in the database
-echo "test4-change1-a" >> tmp-sync/test2a/file1
-touch -t 01011200 tmp-sync/test2a/file1
-
-dav_sync_push test2a "test 4: push failed (1)"
-check_tmpout "1 file pushed" "test 4: wrong push counter (1)"
-check_tmpout "0 conflicts" "test 4: wrong conflict counter (1)"
-check_tmpout "0 errors" "test 4: wrong error counter (1)"
-
-# modify file again and set mtime to same value
-echo "test4-change2-a" >> tmp-sync/test2a/file1
-touch -t 01011200 tmp-sync/test2a/file1
-
-dav_sync_push test2a "test 4: push failed (2)"
-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)"
-
-
-# ----------------------------------------------------------------------------
-# 5. test: set same content on both sides
-# expected result: no conflict
-
-# prepare test2b
-dav_sync_pull test2b "test 5: pull failed"
-check_tmpout "1 file pulled" "test 5: wrong pull counter"
-check_tmpout "0 conflicts" "test 5: wrong conflict counter (prepare)"
-check_tmpout "0 errors" "test 5: wrong error counter (prepare)"
-
-# change content on both sides
-echo "test5-change" >> tmp-sync/test2a/file1
-echo "test5-change" >> tmp-sync/test2b/file1
-
-# push both sides
-dav_sync_push test2a "test 5: push failed (test2a)"
-check_tmpout "1 file pushed" "test 5: wrong push counter (test2a)"
-check_tmpout "0 conflicts" "test 5: wrong conflict counter (test2a)"
-check_tmpout "0 errors" "test 5: wrong error counter (test2a)"
-
-dav_sync_push test2b "test 5: push failed (test2b)"
-# don't check push counter
-check_tmpout "0 conflicts" "test 5: wrong conflict counter (test2b)"
-check_tmpout "0 errors" "test 5: wrong error counter (test2b)"
-
-
-# ----------------------------------------------------------------------------
-# 6. test: upload same new file on both sides
-# expected result: no conflict
-
-echo "test6-newfile" >> tmp-sync/test2a/newfile1
-echo "test6-newfile" >> tmp-sync/test2b/newfile1
-
-# push both sides
-dav_sync_push test2a "test 6: push failed (test2a)"
-check_tmpout "1 file pushed" "test 6: wrong push counter (test2a)"
-check_tmpout "0 conflicts" "test 6: wrong conflict counter (test2a)"
-check_tmpout "0 errors" "test 6: wrong error counter (test2a)"
-
-dav_sync_push test2b "test 6: push failed (test2b)"
-# don't check push counter
-check_tmpout "0 conflicts" "test 6: wrong conflict counter (test2b)"
-check_tmpout "0 errors" "test 6: wrong error counter (test2b)"
-
-
-# ----------------------------------------------------------------------------
-# 7. test: rename file
-# expected result: move
-
-mv tmp-sync/test2a/newfile1 tmp-sync/test2a/move1
-
-dav_sync_push test2a "test 7: push failed"
-check_tmpout "move:" "test 7: no move"
-check_tmpout "0 conflicts" "test 7: wrong conflict counter"
-check_tmpout "0 errors" "test 7: wrong error counter"
-
-
-# ----------------------------------------------------------------------------
-# 8. test: copy file
-# expected result: copy
-
-cp tmp-sync/test2a/file1 tmp-sync/test2a/copy1
-
-dav_sync_push test2a "test 8: push failed"
-check_tmpout "copy:" "test 8: no move"
-check_tmpout "0 conflicts" "test 8: wrong conflict counter"
-check_tmpout "0 errors" "test 8: wrong error counter"
-
-
-# ----------------------------------------------------------------------------
-# 9. test: copy file1 multiple times and than delete it
-# expected result: multiple copies, maybe one move, no errors
-
-echo "test9-change" >> tmp-sync/test2a/file1
-dav_sync_push test2a "test 9: push failed (prepare)"
-check_tmpout "1 file pushed" "test 9: wrong push counter (prepare)"
-check_tmpout "0 conflicts" "test 9: wrong conflict counter (prepare)"
-check_tmpout "0 errors" "test 9: wrong error counter (prepare)"
-
-cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx1
-cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx2
-cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx3
-cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx4
-cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx5
-rm -f tmp-sync/test2a/file1
-
-dav_sync_push test2a "test 9: push failed"
-check_tmpout "copy:" "test 9: no move"
-check_tmpout "0 conflicts" "test 9: wrong conflict counter"
-check_tmpout "0 errors" "test 9: wrong error counter"
-
-# to check if everything worked, pull test2b and check the files
-
-dav_sync_pull test2b
-check_tmpout "0 conflicts" "test 9: wrong conflict counter (pull)"
-check_tmpout "0 errors" "test 9: wrong error counter (pull)"
-
-cat tmp-sync/test2b/file1 > /dev/null 2>&1
-if [ $? -eq 0 ]; then
-	echo "test 9: file1 not deleted (pull)"
-	exit 2
-fi
-
-diff tmp-sync/test2a/copyx1 tmp-sync/test2b/copyx1 > /dev/null 2>&1
-if [ $? -ne 0 ]; then
-	echo "test 9: copyx1 missing or wrong content"
-	exit 2
-fi
-diff tmp-sync/test2a/copyx2 tmp-sync/test2b/copyx2 > /dev/null 2>&1
-if [ $? -ne 0 ]; then
-	echo "test 9: copyx2 missing or wrong content"
-	exit 2
-fi
-diff tmp-sync/test2a/copyx3 tmp-sync/test2b/copyx3 > /dev/null 2>&1
-if [ $? -ne 0 ]; then
-	echo "test 9: copyx3 missing or wrong content"
-	exit 2
-fi
-diff tmp-sync/test2a/copyx4 tmp-sync/test2b/copyx4 > /dev/null 2>&1
-if [ $? -ne 0 ]; then
-	echo "test 9: copyx4 missing or wrong content"
-	exit 2
-fi
-diff tmp-sync/test2a/copyx5 tmp-sync/test2b/copyx5 > /dev/null 2>&1
-if [ $? -ne 0 ]; then
-	echo "test 9: copyx5 missing or wrong content"
-	exit 2
-fi
-
-
-# ----------------------------------------------------------------------------
-# 10. test: rename all copyx files, which will have all the same content hash
-# we don't test if everything is moved (instead of deleted), but to make sure
-# no errors occur when working with files with the same content
-# expected result: no errors
-
-mv tmp-sync/test2a/copyx1 tmp-sync/test2a/movex1
-mv tmp-sync/test2a/copyx2 tmp-sync/test2a/movex2
-mv tmp-sync/test2a/copyx3 tmp-sync/test2a/movex3
-mv tmp-sync/test2a/copyx4 tmp-sync/test2a/movex4
-mv tmp-sync/test2a/copyx5 tmp-sync/test2a/movex5
-
-dav_sync_push test2a "test 10: push failed"
-check_tmpout "move:" "test 10: no move"
-check_tmpout "0 conflicts" "test 10: wrong conflict counter"
-check_tmpout "0 errors" "test 10: wrong error counter"
-
-# to check if everything worked, pull test2b and check the files
-
-dav_sync_pull test2b
-check_tmpout "0 conflicts" "test 9: wrong conflict counter (pull)"
-check_tmpout "0 errors" "test 9: wrong error counter (pull)"
-
-diff tmp-sync/test2a/movex1 tmp-sync/test2b/movex1 > /dev/null 2>&1
-if [ $? -ne 0 ]; then
-	echo "test 10: movex1 missing or wrong content"
-	exit 2
-fi
-diff tmp-sync/test2a/movex2 tmp-sync/test2b/movex2 > /dev/null 2>&1
-if [ $? -ne 0 ]; then
-	echo "test 10: movex2 missing or wrong content"
-	exit 2
-fi
-diff tmp-sync/test2a/movex3 tmp-sync/test2b/movex3 > /dev/null 2>&1
-if [ $? -ne 0 ]; then
-	echo "test 10: movex3 missing or wrong content"
-	exit 2
-fi
-diff tmp-sync/test2a/movex4 tmp-sync/test2b/movex4 > /dev/null 2>&1
-if [ $? -ne 0 ]; then
-	echo "test 10: movex4 missing or wrong content"
-	exit 2
-fi
-diff tmp-sync/test2a/movex5 tmp-sync/test2b/movex5 > /dev/null 2>&1
-if [ $? -ne 0 ]; then
-	echo "test 10: movex5 missing or wrong content"
-	exit 2
-fi
-
-
-# ----------------------------------------------------------------------------
-# 11. test: copy file, push test2a, pull test2b
-# expected result: pull copies file
-
-cp tmp-sync/test2a/movex5 tmp-sync/test2a/newcopyt11
-dav_sync_push test2a "test 11: push failed"
-check_tmpout "copy:" "test 11: no copy (push)"
-check_tmpout "0 conflicts" "test 11: wrong conflict counter (push)"
-check_tmpout "0 errors" "test 11: wrong error counter (push)"
-
-dav_sync_pull test2b "test 11: pull failed"
-check_tmpout "copy:" "test 11: no copy (pull)"
-check_tmpout "0 conflicts" "test 11: wrong conflict counter (pull)"
-check_tmpout "0 errors" "test 11: wrong error counter (pull)"
-
-
-# ----------------------------------------------------------------------------
-# 12. test: move file, push test2a, pull test2b
-# expected result: pull moves file
-
-# we need a fresh file with new content hash for this test
-echo "test12-newfile" >> tmp-sync/test2a/t12file1
-dav_sync_push test2a "test 12: push failed (prepare)"
-check_tmpout "1 file pushed" "test 12: wrong push counter (prepare)"
-check_tmpout "0 conflicts" "test 12: wrong conflict counter (push, prepare)"
-check_tmpout "0 errors" "test 12: wrong error counter (push, prepare)"
-
-dav_sync_pull test2b "test 12: pull failed (prepare)"
-check_tmpout "1 file pulled" "test 12: wrong pull counter (prepare)"
-check_tmpout "0 conflicts" "test 12: wrong conflict counter (pull, prepare)"
-check_tmpout "0 errors" "test 12: wrong error counter (pull, prepare)"
-
-# actual test
-mv tmp-sync/test2a/t12file1 tmp-sync/test2a/t12move1
-dav_sync_push test2a "test 12: push failed"
-check_tmpout "move:" "test 12: no copy (push)"
-check_tmpout "0 conflicts" "test 12: wrong conflict counter (push)"
-check_tmpout "0 errors" "test 12: wrong error counter (push)"
-
-dav_sync_pull test2b "test 12: pull failed"
-check_tmpout "move:" "test 12: no move (pull)"
-check_tmpout "0 conflicts" "test 12: wrong conflict counter (pull)"
-check_tmpout "0 errors" "test 12: wrong error counter (pull)"
-
-
-# ----------------------------------------------------------------------------
-# 13. test: delete file, change name of other file to deleted file's name
-# expected result: first file has content of second file, second file deleted
-
-# prepare
-echo "test13-file1" > tmp-sync/test2a/t13file1
-sleep 3 # make sure t13file2 doesn't has the same mtime as t13file1
-echo "test13-file2" > tmp-sync/test2a/t13file2
-
-dav_sync_push test2a "test 13: push failed (prepare)"
-check_tmpout "2 files pushed" "test 13: wrong push counter (prepare, push)"
-check_tmpout "0 conflicts" "test 13: wrong conflict counter (prepare, push)"
-check_tmpout "0 errors" "test 13: wrong error counter (prepare, push)"
-
-dav_sync_pull test2b "test 13: pull failed (prepare)"
-check_tmpout "2 files pulled" "test 13: wrong pull counter (prepare, pull)"
-check_tmpout "0 conflicts" "test 13: wrong conflict counter (prepare, pull)"
-check_tmpout "0 errors" "test 13: wrong error counter (prepare, pull)"
-
-# do test
-rm -f tmp-sync/test2a/t13file1
-mv tmp-sync/test2a/t13file2 tmp-sync/test2a/t13file1
-
-sleep 2
-
-dav_sync_push test2a "test 13: push failed"
-# we can't check the exact output, because there are multiple valid ways
-# to sync the changes
-check_tmpout "0 conflicts" "test 13: wrong conflict counter (push)"
-check_tmpout "0 errors" "test 13: wrong error counter (push)"
-
-dav_sync_pull test2b "test 13: pull failed"
-check_tmpout "0 conflicts" "test 13: wrong conflict counter (pull)"
-check_tmpout "0 errors" "test 13: wrong error counter (pull)"
-
-TEST=`cat tmp-sync/test2b/t13file1`
-if  [ $TEST != "test13-file2" ]; then
-	echo "test 13: t13file1 has wrong content"
-	exit 2
-fi
-
-cat tmp-sync/test2b/t13file2 > /dev/null 2>&1
-if [ $? -eq 0 ]; then
-	echo "test 13: t13file2 not deleted"
-	exit 2
-fi
-
-
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bin-test/test-dav-sync-hashing1.sh	Sun Oct 06 13:27:24 2019 +0200
@@ -0,0 +1,440 @@
+#!/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
+
+# ----------------------------------------------------------------------------
+# 1. test: add 4 files, push, pull (not really an hashing test)
+# expected result: 4 files pushed, 4 files pulled
+
+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
+
+dav_sync_push test2a "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 test2b "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)"
+
+
+# ----------------------------------------------------------------------------
+# 2. test: touch 2 files, push
+# expected result: 0 files pushed
+
+sleep 3
+
+touch tmp-sync/test2a/file1
+touch tmp-sync/test2a/dir1/file2
+
+dav_sync_push test2a "test 2: push failed"
+check_tmpout "0 files pushed" "test 2: wrong push counter"
+check_tmpout "0 conflicts" "test 2: wrong conflict counter"
+check_tmpout "0 errors" "test 2: wrong error counter"
+
+
+# ----------------------------------------------------------------------------
+# 3. test: copy file1 to test2a again
+# expected result: 0 files pushed
+
+sleep 3
+
+cp synctest/file1 tmp-sync/test2a/
+
+dav_sync_push test2a "test 3: push failed"
+check_tmpout "0 files pushed" "test 3: wrong push counter"
+check_tmpout "0 conflicts" "test 3: wrong conflict counter"
+check_tmpout "0 errors" "test 3: wrong error counter"
+
+
+# ----------------------------------------------------------------------------
+# 4. test: change content but don't change mtime
+# expected result: 1 file pushed
+
+# modify file and mtime to update mtime in the database
+echo "test4-change1-a" >> tmp-sync/test2a/file1
+touch -t 01011200 tmp-sync/test2a/file1
+
+dav_sync_push test2a "test 4: push failed (1)"
+check_tmpout "1 file pushed" "test 4: wrong push counter (1)"
+check_tmpout "0 conflicts" "test 4: wrong conflict counter (1)"
+check_tmpout "0 errors" "test 4: wrong error counter (1)"
+
+# modify file again and set mtime to same value
+echo "test4-change2-a" >> tmp-sync/test2a/file1
+touch -t 01011200 tmp-sync/test2a/file1
+
+dav_sync_push test2a "test 4: push failed (2)"
+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)"
+
+
+# ----------------------------------------------------------------------------
+# 5. test: set same content on both sides
+# expected result: no conflict
+
+# prepare test2b
+dav_sync_pull test2b "test 5: pull failed"
+check_tmpout "1 file pulled" "test 5: wrong pull counter"
+check_tmpout "0 conflicts" "test 5: wrong conflict counter (prepare)"
+check_tmpout "0 errors" "test 5: wrong error counter (prepare)"
+
+# change content on both sides
+echo "test5-change" >> tmp-sync/test2a/file1
+echo "test5-change" >> tmp-sync/test2b/file1
+
+# push both sides
+dav_sync_push test2a "test 5: push failed (test2a)"
+check_tmpout "1 file pushed" "test 5: wrong push counter (test2a)"
+check_tmpout "0 conflicts" "test 5: wrong conflict counter (test2a)"
+check_tmpout "0 errors" "test 5: wrong error counter (test2a)"
+
+dav_sync_push test2b "test 5: push failed (test2b)"
+# don't check push counter
+check_tmpout "0 conflicts" "test 5: wrong conflict counter (test2b)"
+check_tmpout "0 errors" "test 5: wrong error counter (test2b)"
+
+
+# ----------------------------------------------------------------------------
+# 6. test: upload same new file on both sides
+# expected result: no conflict
+
+echo "test6-newfile" >> tmp-sync/test2a/newfile1
+echo "test6-newfile" >> tmp-sync/test2b/newfile1
+
+# push both sides
+dav_sync_push test2a "test 6: push failed (test2a)"
+check_tmpout "1 file pushed" "test 6: wrong push counter (test2a)"
+check_tmpout "0 conflicts" "test 6: wrong conflict counter (test2a)"
+check_tmpout "0 errors" "test 6: wrong error counter (test2a)"
+
+dav_sync_push test2b "test 6: push failed (test2b)"
+# don't check push counter
+check_tmpout "0 conflicts" "test 6: wrong conflict counter (test2b)"
+check_tmpout "0 errors" "test 6: wrong error counter (test2b)"
+
+
+# ----------------------------------------------------------------------------
+# 7. test: rename file
+# expected result: move
+
+mv tmp-sync/test2a/newfile1 tmp-sync/test2a/move1
+
+dav_sync_push test2a "test 7: push failed"
+check_tmpout "move:" "test 7: no move"
+check_tmpout "0 conflicts" "test 7: wrong conflict counter"
+check_tmpout "0 errors" "test 7: wrong error counter"
+
+
+# ----------------------------------------------------------------------------
+# 8. test: copy file
+# expected result: copy
+
+cp tmp-sync/test2a/file1 tmp-sync/test2a/copy1
+
+dav_sync_push test2a "test 8: push failed"
+check_tmpout "copy:" "test 8: no move"
+check_tmpout "0 conflicts" "test 8: wrong conflict counter"
+check_tmpout "0 errors" "test 8: wrong error counter"
+
+
+# ----------------------------------------------------------------------------
+# 9. test: copy file1 multiple times and than delete it
+# expected result: multiple copies, maybe one move, no errors
+
+echo "test9-change" >> tmp-sync/test2a/file1
+dav_sync_push test2a "test 9: push failed (prepare)"
+check_tmpout "1 file pushed" "test 9: wrong push counter (prepare)"
+check_tmpout "0 conflicts" "test 9: wrong conflict counter (prepare)"
+check_tmpout "0 errors" "test 9: wrong error counter (prepare)"
+
+cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx1
+cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx2
+cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx3
+cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx4
+cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx5
+rm -f tmp-sync/test2a/file1
+
+dav_sync_push test2a "test 9: push failed"
+check_tmpout "copy:" "test 9: no move"
+check_tmpout "0 conflicts" "test 9: wrong conflict counter"
+check_tmpout "0 errors" "test 9: wrong error counter"
+
+# to check if everything worked, pull test2b and check the files
+
+dav_sync_pull test2b
+check_tmpout "0 conflicts" "test 9: wrong conflict counter (pull)"
+check_tmpout "0 errors" "test 9: wrong error counter (pull)"
+
+cat tmp-sync/test2b/file1 > /dev/null 2>&1
+if [ $? -eq 0 ]; then
+	echo "test 9: file1 not deleted (pull)"
+	exit 2
+fi
+
+diff tmp-sync/test2a/copyx1 tmp-sync/test2b/copyx1 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 9: copyx1 missing or wrong content"
+	exit 2
+fi
+diff tmp-sync/test2a/copyx2 tmp-sync/test2b/copyx2 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 9: copyx2 missing or wrong content"
+	exit 2
+fi
+diff tmp-sync/test2a/copyx3 tmp-sync/test2b/copyx3 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 9: copyx3 missing or wrong content"
+	exit 2
+fi
+diff tmp-sync/test2a/copyx4 tmp-sync/test2b/copyx4 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 9: copyx4 missing or wrong content"
+	exit 2
+fi
+diff tmp-sync/test2a/copyx5 tmp-sync/test2b/copyx5 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 9: copyx5 missing or wrong content"
+	exit 2
+fi
+
+
+# ----------------------------------------------------------------------------
+# 10. test: rename all copyx files, which will have all the same content hash
+# we don't test if everything is moved (instead of deleted), but to make sure
+# no errors occur when working with files with the same content
+# expected result: no errors
+
+mv tmp-sync/test2a/copyx1 tmp-sync/test2a/movex1
+mv tmp-sync/test2a/copyx2 tmp-sync/test2a/movex2
+mv tmp-sync/test2a/copyx3 tmp-sync/test2a/movex3
+mv tmp-sync/test2a/copyx4 tmp-sync/test2a/movex4
+mv tmp-sync/test2a/copyx5 tmp-sync/test2a/movex5
+
+dav_sync_push test2a "test 10: push failed"
+check_tmpout "move:" "test 10: no move"
+check_tmpout "0 conflicts" "test 10: wrong conflict counter"
+check_tmpout "0 errors" "test 10: wrong error counter"
+
+# to check if everything worked, pull test2b and check the files
+
+dav_sync_pull test2b
+check_tmpout "0 conflicts" "test 9: wrong conflict counter (pull)"
+check_tmpout "0 errors" "test 9: wrong error counter (pull)"
+
+diff tmp-sync/test2a/movex1 tmp-sync/test2b/movex1 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 10: movex1 missing or wrong content"
+	exit 2
+fi
+diff tmp-sync/test2a/movex2 tmp-sync/test2b/movex2 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 10: movex2 missing or wrong content"
+	exit 2
+fi
+diff tmp-sync/test2a/movex3 tmp-sync/test2b/movex3 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 10: movex3 missing or wrong content"
+	exit 2
+fi
+diff tmp-sync/test2a/movex4 tmp-sync/test2b/movex4 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 10: movex4 missing or wrong content"
+	exit 2
+fi
+diff tmp-sync/test2a/movex5 tmp-sync/test2b/movex5 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 10: movex5 missing or wrong content"
+	exit 2
+fi
+
+
+# ----------------------------------------------------------------------------
+# 11. test: copy file, push test2a, pull test2b
+# expected result: pull copies file
+
+cp tmp-sync/test2a/movex5 tmp-sync/test2a/newcopyt11
+dav_sync_push test2a "test 11: push failed"
+check_tmpout "copy:" "test 11: no copy (push)"
+check_tmpout "0 conflicts" "test 11: wrong conflict counter (push)"
+check_tmpout "0 errors" "test 11: wrong error counter (push)"
+
+dav_sync_pull test2b "test 11: pull failed"
+check_tmpout "copy:" "test 11: no copy (pull)"
+check_tmpout "0 conflicts" "test 11: wrong conflict counter (pull)"
+check_tmpout "0 errors" "test 11: wrong error counter (pull)"
+
+
+# ----------------------------------------------------------------------------
+# 12. test: move file, push test2a, pull test2b
+# expected result: pull moves file
+
+# we need a fresh file with new content hash for this test
+echo "test12-newfile" >> tmp-sync/test2a/t12file1
+dav_sync_push test2a "test 12: push failed (prepare)"
+check_tmpout "1 file pushed" "test 12: wrong push counter (prepare)"
+check_tmpout "0 conflicts" "test 12: wrong conflict counter (push, prepare)"
+check_tmpout "0 errors" "test 12: wrong error counter (push, prepare)"
+
+dav_sync_pull test2b "test 12: pull failed (prepare)"
+check_tmpout "1 file pulled" "test 12: wrong pull counter (prepare)"
+check_tmpout "0 conflicts" "test 12: wrong conflict counter (pull, prepare)"
+check_tmpout "0 errors" "test 12: wrong error counter (pull, prepare)"
+
+# actual test
+mv tmp-sync/test2a/t12file1 tmp-sync/test2a/t12move1
+dav_sync_push test2a "test 12: push failed"
+check_tmpout "move:" "test 12: no copy (push)"
+check_tmpout "0 conflicts" "test 12: wrong conflict counter (push)"
+check_tmpout "0 errors" "test 12: wrong error counter (push)"
+
+dav_sync_pull test2b "test 12: pull failed"
+check_tmpout "move:" "test 12: no move (pull)"
+check_tmpout "0 conflicts" "test 12: wrong conflict counter (pull)"
+check_tmpout "0 errors" "test 12: wrong error counter (pull)"
+
+
+# ----------------------------------------------------------------------------
+# 13. test: delete file, change name of other file to deleted file's name
+# expected result: first file has content of second file, second file deleted
+
+# prepare
+echo "test13-file1" > tmp-sync/test2a/t13file1
+sleep 3 # make sure t13file2 doesn't has the same mtime as t13file1
+echo "test13-file2" > tmp-sync/test2a/t13file2
+
+dav_sync_push test2a "test 13: push failed (prepare)"
+check_tmpout "2 files pushed" "test 13: wrong push counter (prepare, push)"
+check_tmpout "0 conflicts" "test 13: wrong conflict counter (prepare, push)"
+check_tmpout "0 errors" "test 13: wrong error counter (prepare, push)"
+
+dav_sync_pull test2b "test 13: pull failed (prepare)"
+check_tmpout "2 files pulled" "test 13: wrong pull counter (prepare, pull)"
+check_tmpout "0 conflicts" "test 13: wrong conflict counter (prepare, pull)"
+check_tmpout "0 errors" "test 13: wrong error counter (prepare, pull)"
+
+# do test
+rm -f tmp-sync/test2a/t13file1
+mv tmp-sync/test2a/t13file2 tmp-sync/test2a/t13file1
+
+sleep 2
+
+dav_sync_push test2a "test 13: push failed"
+# we can't check the exact output, because there are multiple valid ways
+# to sync the changes
+check_tmpout "0 conflicts" "test 13: wrong conflict counter (push)"
+check_tmpout "0 errors" "test 13: wrong error counter (push)"
+
+dav_sync_pull test2b "test 13: pull failed"
+check_tmpout "0 conflicts" "test 13: wrong conflict counter (pull)"
+check_tmpout "0 errors" "test 13: wrong error counter (pull)"
+
+TEST=`cat tmp-sync/test2b/t13file1`
+if  [ $TEST != "test13-file2" ]; then
+	echo "test 13: t13file1 has wrong content"
+	exit 2
+fi
+
+cat tmp-sync/test2b/t13file2 > /dev/null 2>&1
+if [ $? -eq 0 ]; then
+	echo "test 13: t13file2 not deleted"
+	exit 2
+fi
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bin-test/test-dav-sync-hashing2.sh	Sun Oct 06 13:27:24 2019 +0200
@@ -0,0 +1,149 @@
+#!/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 2 equal files
+# expected result: 2 files pushed
+
+mkdir tmp-sync/test2a/dir1/
+mkdir tmp-sync/test2a/dir1/subdir1/
+
+echo "equal-file" > tmp-sync/test2a/file1
+echo "equal-file" > tmp-sync/test2a/file2
+
+dav_sync_push test2a "test 1: push failed"
+check_tmpout "2 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 test2b "test 1: pull failed"
+check_tmpout "2 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: add file3 with same content, but change file1 and file2
+# expected result: pull: no copy/move for file3
+
+echo "equal-file" > tmp-sync/test2a/file3
+
+echo "change-test2" >> tmp-sync/test2a/file1
+echo "change-test2" >> tmp-sync/test2a/file2
+
+sleep 2 # make sure the etag changes
+
+dav_sync_push test2a "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)"
+
+dav_sync_pull test2b "test 3: 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)"
+
+diff tmp-sync/test2a/file1 tmp-sync/test2b/file1 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 2: file1 missing or wrong content"
+	exit 2
+fi
+diff tmp-sync/test2a/file2 tmp-sync/test2b/file2 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 2: file1 missing or wrong content"
+	exit 2
+fi
+diff tmp-sync/test2a/file3 tmp-sync/test2b/file3 > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+	echo "test 2: file1 missing or wrong content"
+	exit 2
+fi
+
--- a/test/bin-test/test-dav-sync.sh	Thu Oct 03 12:00:25 2019 +0200
+++ b/test/bin-test/test-dav-sync.sh	Sun Oct 06 13:27:24 2019 +0200
@@ -97,8 +97,10 @@
 do_test "dav-sync pull (1)" test-dav-sync-pull1.sh
 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 hashing (1)" test-dav-sync-hashing1.sh
+do_test "dav-sync hashing (2)" test-dav-sync-hashing1.sh
 do_test "dav-sync hash strategy" test-dav-sync-hash-strategy.sh
+do_test "dav-sync hash conflict resolution" test-dav-sync-hash-conflictres.sh
 
 # cleanup
 $DAV_BIN rm dav-test-repo/sync/test1 > /dev/null 2>&1

mercurial