# HG changeset patch # User Olaf Wintermann # Date 1567871150 -7200 # Node ID b3077bdb3d7704df24f58fec1416af50d71503e9 # Parent 20241338740c061fdec40d159f6874d71a0b05ba fix hash based conflict detection diff -r 20241338740c -r b3077bdb3d77 dav/db.c --- a/dav/db.c Wed Sep 04 19:28:10 2019 +0200 +++ b/dav/db.c Sat Sep 07 17:45:50 2019 +0200 @@ -717,6 +717,9 @@ if(res->tags_hash) { free(res->tags_hash); } + if(res->prev_hash) { + free(res->prev_hash); + } free(res); } diff -r 20241338740c -r b3077bdb3d77 dav/db.h --- a/dav/db.h Wed Sep 04 19:28:10 2019 +0200 +++ b/dav/db.h Sat Sep 07 17:45:50 2019 +0200 @@ -89,6 +89,8 @@ DavBool isnew; LocalResource *origin; char *conflict_source; + + char *prev_hash; }; struct FilePart { diff -r 20241338740c -r b3077bdb3d77 dav/sync.c --- a/dav/sync.c Wed Sep 04 19:28:10 2019 +0200 +++ b/dav/sync.c Sat Sep 07 17:45:50 2019 +0200 @@ -2749,6 +2749,9 @@ if(db_res->xattr_hash) { res->xattr_hash = strdup(db_res->xattr_hash); } + if(db_res->hash) { + res->prev_hash = strdup(db_res->hash); + } // if the resource is splitted, move the part infos to the new // LocalResource obj, because we need it later @@ -2885,8 +2888,8 @@ if(err == 0) { char *etag = dav_get_string_property(remote, "D:getetag"); char *hash = sync_get_content_hash(remote); - if(hash && res->hash) { - if(strcmp(hash, res->hash)) { + if(hash && res->prev_hash) { + if(strcmp(hash, res->prev_hash)) { ret = 1; } } else if(!res->etag) { diff -r 20241338740c -r b3077bdb3d77 libidav/methods.c --- a/libidav/methods.c Wed Sep 04 19:28:10 2019 +0200 +++ b/libidav/methods.c Sat Sep 07 17:45:50 2019 +0200 @@ -783,7 +783,7 @@ char *lock, UcxBuffer *request, UcxBuffer *response) -{ +{ CURL *handle = sn->handle; curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPPATCH"); diff -r 20241338740c -r b3077bdb3d77 test/bin-test/test-dav-sync-hashing.sh --- a/test/bin-test/test-dav-sync-hashing.sh Wed Sep 04 19:28:10 2019 +0200 +++ b/test/bin-test/test-dav-sync-hashing.sh Sat Sep 07 17:45:50 2019 +0200 @@ -90,7 +90,7 @@ mkdir tmp-sync/test2b # ---------------------------------------------------------------------------- -# 1. test: add 4 files, push, pull +# 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/ @@ -112,4 +112,53 @@ 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)" diff -r 20241338740c -r b3077bdb3d77 test/bin-test/test-dav-sync-push-conflict.sh --- a/test/bin-test/test-dav-sync-push-conflict.sh Wed Sep 04 19:28:10 2019 +0200 +++ b/test/bin-test/test-dav-sync-push-conflict.sh Sat Sep 07 17:45:50 2019 +0200 @@ -558,7 +558,7 @@ # ---------------------------------------------------------------------------- -# 16. modify file in test1a/dir1/, delete dir1 in test1b +# 16. test: modify file in test1a/dir1/, delete dir1 in test1b # expected result: many files deleted, modified file not deleted sleep 3