introduces SyncTagFilter type which for now implements the old tag list filter

Wed, 30 May 2018 12:10:58 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 30 May 2018 12:10:58 +0200
changeset 389
fe855ce911f9
parent 388
0b96ae226838
child 390
26998dc980f9

introduces SyncTagFilter type which for now implements the old tag list filter

dav/libxattr.c file | annotate | diff | comparison | revisions
dav/sync.c file | annotate | diff | comparison | revisions
dav/sync.h file | annotate | diff | comparison | revisions
--- a/dav/libxattr.c	Wed May 30 11:26:28 2018 +0200
+++ b/dav/libxattr.c	Wed May 30 12:10:58 2018 +0200
@@ -43,7 +43,7 @@
 #define ATTR_BUF_LEN 1024
 
 #define ARRAY_ADD(array, pos, len, obj) if(pos >= len) { \
-        len *= 2; \
+        len *= 2; /* TODO: missing error handling for realloc() */ \
         array = realloc(array, len * sizeof(char*)); \
     } \
     array[pos] = obj; \
--- 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;
--- a/dav/sync.h	Wed May 30 11:26:28 2018 +0200
+++ b/dav/sync.h	Wed May 30 12:10:58 2018 +0200
@@ -111,6 +111,10 @@
 int cmd_trash_info(CmdArgs *args);
 int cmd_empty_trash(CmdArgs *args);
 
+typedef struct {
+    UcxList* tags;
+} SyncTagFilter;
+
 int cmd_add_tag(CmdArgs *args);
 int cmd_remove_tag(CmdArgs *args);
 int cmd_set_tags(CmdArgs *args);

mercurial