dav/sync.c

changeset 557
90ad7324bbbc
parent 556
1a58014260e0
child 558
1a9e6a5c1e79
--- a/dav/sync.c	Sun Apr 07 17:35:52 2019 +0200
+++ b/dav/sync.c	Sun Apr 07 17:56:31 2019 +0200
@@ -101,6 +101,12 @@
     return strcmp(s1, s2);
 }
 
+static void nullfree(void *p) {
+    if(p) {
+        free(p);
+    }
+}
+
 int main(int argc, char **argv) {
     if(argc < 2) {
         fprintf(stderr, "Missing command\n");
@@ -1713,6 +1719,10 @@
             if(cdt && changed) {
                 printf("conflict: %s\n", local_res->path);
                 local_res->last_modified = 0;
+                nullfree(local_res->etag);
+                local_res->etag = NULL;
+                nullfree(local_res->hash);
+                local_res->hash = NULL;
                 local_res->skipped = TRUE;
                 sync_skipped++;
             } else {
@@ -1744,6 +1754,12 @@
         DavResource *res = dav_resource_new(sn, local->path);
         if(dav_exists(res)) {
             printf("conflict: %s\n", local->path);
+            local->last_modified = 0;
+            nullfree(local->etag);
+            local->etag = NULL;
+            nullfree(local->hash);
+            local->hash = NULL;
+            local->skipped = TRUE;
             sync_skipped++;
         } else {
             DavResource *origin_res = dav_resource_new(sn, local->origin->path);
@@ -2378,8 +2394,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(!nullstrcmp(hash, res->hash)) {
+        if(hash && res->hash) {
+            if(!strcmp(hash, res->hash)) {
                 ret = 1;
             }
         } else if(!res->etag) {

mercurial