fixes conflict detection in push command

Fri, 02 Dec 2016 13:24:01 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 02 Dec 2016 13:24:01 +0100
changeset 257
49f3c58cc06c
parent 256
54433cb371df
child 258
571b62700df6

fixes conflict detection in push command

dav/db.c file | annotate | diff | comparison | revisions
dav/db.h file | annotate | diff | comparison | revisions
dav/sync.c file | annotate | diff | comparison | revisions
--- a/dav/db.c	Fri Nov 18 16:00:15 2016 +0100
+++ b/dav/db.c	Fri Dec 02 13:24:01 2016 +0100
@@ -122,6 +122,8 @@
                 field = 2;
             } else if(xstreq(name, "size")) {
                 field = 3;
+            } else if(xstreq(name, "skipped")) {
+                res->skipped = TRUE;
             }
         } else if(type == XML_READER_TYPE_TEXT) {
             const xmlChar *value = xmlTextReaderConstValue(reader);
@@ -276,6 +278,16 @@
             return -1;
         }
         
+        if(res->skipped) {
+            r = xmlTextWriterStartElement(writer, "skipped");
+            r += xmlTextWriterEndElement(writer);
+            if(r < 0) {
+                fprintf(stderr, "Cannot write skipped: %s\n");
+                xmlFreeTextWriter(writer);
+                return -1;
+            }
+        }
+        
         // </resource>
         xmlTextWriterEndElement(writer);
     }
--- a/dav/db.h	Fri Nov 18 16:00:15 2016 +0100
+++ b/dav/db.h	Fri Dec 02 13:24:01 2016 +0100
@@ -49,6 +49,7 @@
     time_t  last_modified;
     off_t   size;
     DavBool isdirectory;
+    DavBool skipped;
 };
 
 struct SyncDatabase {
--- a/dav/sync.c	Fri Nov 18 16:00:15 2016 +0100
+++ b/dav/sync.c	Fri Dec 02 13:24:01 2016 +0100
@@ -525,6 +525,7 @@
             local->etag = strdup(etag);
             local->last_modified = s.st_mtime;
             local->size = s.st_size;
+            local->skipped = FALSE;
         } else {
             if(unlink(tmp_path)) {
                 fprintf(stderr, "Cannot remove tmp file: %s\n", tmp_path);
@@ -807,16 +808,17 @@
                 } else {
                     if(cdt && remote_resource_is_changed(sn, dir, db, local_res)) {
                         printf("conflict: %s\n", local_res->path);
+                        local_res->last_modified = 0;
+                        local_res->skipped = TRUE;
                         sync_skipped++;
-                        continue;
-                    }
-                    
-                    printf("put: %s\n", local_res->path);
-                    if(sync_put_resource(dir, res, local_res, &sync_success)) {
-                        sync_error++;
-                        print_resource_error(sn, res->path);
-                        ret = -1;
-                        error = 1;
+                    } else {
+                        printf("put: %s\n", local_res->path);
+                        if(sync_put_resource(dir, res, local_res, &sync_success)) {
+                            sync_error++;
+                            print_resource_error(sn, res->path);
+                            ret = -1;
+                            error = 1;
+                        }
                     }
                 }
                 dav_resource_free(res);
@@ -1258,6 +1260,24 @@
     free(dc);
 }
 
+static void resolve_skipped(SyncDatabase *db) {
+    UcxKey k;
+    LocalResource *res;
+    UcxMapIterator i = ucx_map_iterator(db->resources);
+    int skipped = 0;
+    UCX_MAP_FOREACH(k, res, i) {
+        if(res->skipped) {
+            skipped++;
+            fprintf(stderr, "skipped from push: %s\n", res->path);
+        }
+    }
+    if(skipped > 0) {
+        fprintf(stderr,
+                "  To resolve conflict resources skipped by push run dav-sync pull first\n"
+                "  before resolve-conflicts or delete-conflicts.\n\n");
+    }
+}
+
 int cmd_resolve_conflicts(CmdArgs *a) {
     if(a->argc != 1) {
         fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
@@ -1279,6 +1299,8 @@
         return -1;
     }
     
+    resolve_skipped(db);
+    
     int ret = 0;
     
     // remove conflicts
@@ -1326,6 +1348,8 @@
         return -1;
     }
     
+    resolve_skipped(db);
+    
     int num_del = 0;
     int num_err = 0;
     

mercurial