fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)

Sat, 07 Sep 2019 19:25:51 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 07 Sep 2019 19:25:51 +0200
changeset 639
928a77ebe0b9
parent 638
b3077bdb3d77
child 640
65e40934b26c

fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)

dav/sync.c file | annotate | diff | comparison | revisions
dav/sync.h file | annotate | diff | comparison | revisions
test/bin-test/test-dav-sync-hashing.sh file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Sat Sep 07 17:45:50 2019 +0200
+++ b/dav/sync.c	Sat Sep 07 19:25:51 2019 +0200
@@ -2081,7 +2081,8 @@
                     dir,
                     db,
                     origin_res,
-                    local->origin);
+                    local->origin,
+                    NULL);
             if(origin_changed) {
                 // upload with put
                 ls_modified = ucx_list_prepend(ls_modified, local);               
@@ -2127,8 +2128,13 @@
             ret = -1;
             sync_error++;
         } else {
-            int changed = remote_resource_is_changed(sn, dir, db, res, local_res);
-            if(cdt && changed) {
+            DavBool equal = FALSE;
+            int changed = remote_resource_is_changed(sn, dir, db, res, local_res, &equal);
+            if(equal) {
+                if(local_res->metadata_updated) {
+                    ls_update = ucx_list_prepend(ls_update, local_res);
+                }
+            } else if(cdt && changed) {
                 printf("conflict: %s\n", local_res->path);
                 local_res->last_modified = 0;
                 nullfree(local_res->etag);
@@ -2864,8 +2870,13 @@
         SyncDirectory *dir,
         SyncDatabase *db,
         DavResource *remote,
-        LocalResource *res)
+        LocalResource *res,
+        DavBool *equal)
 {
+    if(equal) {
+        *equal = FALSE;
+    }
+    
     DavPropName properties[] = {
         {"DAV:", "getetag"},
         {DAV_NS, "version-collection"},
@@ -2888,6 +2899,15 @@
     if(err == 0) {
         char *etag = dav_get_string_property(remote, "D:getetag");
         char *hash = sync_get_content_hash(remote);
+        
+        if(hash && res->hash && equal) {
+            // if requested, check if the local and remote are equal
+            if(!strcmp(hash, res->hash)) {
+                *equal = TRUE;
+                return 0;
+            }
+        }
+        
         if(hash && res->prev_hash) {
             if(strcmp(hash, res->prev_hash)) {
                 ret = 1;
--- a/dav/sync.h	Sat Sep 07 17:45:50 2019 +0200
+++ b/dav/sync.h	Sat Sep 07 19:25:51 2019 +0200
@@ -150,7 +150,8 @@
         SyncDirectory *dir,
         SyncDatabase *db,
         DavResource *remote,
-        LocalResource *res);
+        LocalResource *res,
+        DavBool *equal);
 int local_resource_load_metadata(SyncDirectory *dir, LocalResource *res);
 
 void local_resource_set_etag(LocalResource *local, const char *etag);
--- a/test/bin-test/test-dav-sync-hashing.sh	Sat Sep 07 17:45:50 2019 +0200
+++ b/test/bin-test/test-dav-sync-hashing.sh	Sat Sep 07 19:25:51 2019 +0200
@@ -162,3 +162,29 @@
 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)"

mercurial