dav/sync.c

changeset 389
fe855ce911f9
parent 386
99193580aa9d
child 390
26998dc980f9
--- a/dav/sync.c	Wed May 30 11:26:28 2018 +0200
+++ b/dav/sync.c	Wed May 30 12:10:58 2018 +0200
@@ -255,10 +255,7 @@
     return 1;
 }
 
-static int matches_tags(UcxList *resource_tags, UcxList *tags) {
-    if(!tags) {
-        return 1;
-    }
+static int matches_tags(UcxList *resource_tags, SyncTagFilter *tagfilter) {
     if(!resource_tags) {
         return 0;
     }
@@ -273,7 +270,7 @@
     int ret = 1;
     
     // TODO: replace FOREACH with new tag expression evaluation
-    UCX_FOREACH(elm, tags) {
+    UCX_FOREACH(elm, tagfilter->tags) {
         DavTag *matches_tag = elm->data;
         if(!ucx_map_cstr_get(res_tagmap, matches_tag->name)) {
             ret = 0;
@@ -285,21 +282,25 @@
     return ret;
 }
 
-static int res_matches_tags(DavResource *res, UcxList *tags) {
-    if(!tags) {
+static int res_matches_tags(DavResource *res, SyncTagFilter *tagfilter) {
+    if(!tagfilter) {
         return 1;
     }
     
     DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_NS, "tags");
     UcxList *res_tags = parse_dav_xml_taglist(tagsprop);
     
-    int ret = matches_tags(res_tags, tags);
+    int ret = matches_tags(res_tags, tagfilter);
     // TODO: free list content
     ucx_list_free(res_tags);
     return ret;
 }
 
-static int localres_matches_tags(LocalResource *res, UcxList *tags) {
+static int localres_matches_tags(LocalResource *res, SyncTagFilter *tagfilter) {
+    if(!tagfilter) {
+        return 1;
+    }
+    
     // TODO: implement
     return 1;
 }
@@ -454,13 +455,6 @@
         return -1;
     }
     
-    UcxList *tags = NULL;
-    char *tags_str = cmd_getoption(a, "tags");
-    if(tags_str) {
-        tags = parse_csv_taglist(tags_str, strlen(tags_str));
-    }
-    DavBool rm_tagmismatch = cmd_getoption(a, "remove") ? 1 : 0;
-    
     int sync_success = 0;
     int sync_delete = 0;
     int sync_error = 0;
@@ -480,8 +474,15 @@
                 continue;
             }
             
-            if (!res_matches_tags(res, tags)) {
-                if(!rm_tagmismatch) {
+            
+            SyncTagFilter tagfilter;
+            tagfilter.tags = NULL;
+            char *tags_str = cmd_getoption(a, "tags");
+            if(tags_str) {
+                tagfilter.tags = parse_csv_taglist(tags_str, strlen(tags_str));
+            }
+            if (!res_matches_tags(res, &tagfilter)) {
+                if(!cmd_getoption(a, "remove")) {
                     localres_keep(db, res->path);
                 }
                 res = res->next;

mercurial