adds tagfilter scope

Mon, 11 Jun 2018 19:31:03 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 11 Jun 2018 19:31:03 +0200
changeset 414
ea50585ec9d9
parent 413
241db665477a
child 415
6e1861e8262c

adds tagfilter scope

dav/scfg.c file | annotate | diff | comparison | revisions
dav/sync.c file | annotate | diff | comparison | revisions
dav/tags.c file | annotate | diff | comparison | revisions
dav/tags.h file | annotate | diff | comparison | revisions
--- a/dav/scfg.c	Sun Jun 10 13:24:30 2018 +0200
+++ b/dav/scfg.c	Mon Jun 11 19:31:03 2018 +0200
@@ -113,7 +113,8 @@
                 }
             } else if(xstreq(node->name, "tags")) {
                 if(value) {
-                    *tagfilter = parse_tagfilter_string(value);
+                    *tagfilter = parse_tagfilter_string(
+                            value, DAV_SYNC_TAGFILTER_SCOPE_RESOURCE);
                     if(!*tagfilter) {
                         print_error(
                                 node->line,
--- a/dav/sync.c	Sun Jun 10 13:24:30 2018 +0200
+++ b/dav/sync.c	Mon Jun 11 19:31:03 2018 +0200
@@ -259,6 +259,12 @@
 }
 
 static int res_matches_tags(DavResource *res, SyncTagFilter *tagfilter) {
+    int scope = res->iscollection ?
+            DAV_SYNC_TAGFILTER_SCOPE_COLLECTION
+          : DAV_SYNC_TAGFILTER_SCOPE_RESOURCE;
+    if(tagfilter->scope & scope != scope) {
+        return 1;
+    }
     if(!tagfilter || tagfilter->mode == DAV_SYNC_TAGFILTER_OFF) {
         return 1;
     }
@@ -279,6 +285,12 @@
         LocalResource *res,
         SyncTagFilter *tagfilter)
 {
+    int scope = res->isdirectory ?
+            DAV_SYNC_TAGFILTER_SCOPE_COLLECTION
+          : DAV_SYNC_TAGFILTER_SCOPE_RESOURCE;
+    if(tagfilter->scope & scope != scope) {
+        return 1;
+    }
     if(!tagfilter || tagfilter->mode == DAV_SYNC_TAGFILTER_OFF) {
         return 1;
     }
@@ -346,7 +358,8 @@
         return -1;
     }
     // if there are syntax errors in the command line, fail asap.
-    SyncTagFilter* tagfilter = parse_tagfilter_string(cmd_getoption(a, "tags"));
+    SyncTagFilter* tagfilter = parse_tagfilter_string(
+            cmd_getoption(a, "tags"), DAV_SYNC_TAGFILTER_SCOPE_RESOURCE);
     if (!tagfilter) {
         fprintf(stderr, "Malformed tag filter\n");
         return -1;
@@ -917,7 +930,8 @@
     }
     
     // if there are syntax errors in the command line, fail asap.
-    SyncTagFilter* tagfilter = parse_tagfilter_string(cmd_getoption(a, "tags"));
+    SyncTagFilter* tagfilter = parse_tagfilter_string(
+            cmd_getoption(a, "tags"), DAV_SYNC_TAGFILTER_SCOPE_RESOURCE);
     if (!tagfilter) {
         fprintf(stderr, "Malformed tag filter\n");
         return -1;
--- a/dav/tags.c	Sun Jun 10 13:24:30 2018 +0200
+++ b/dav/tags.c	Mon Jun 11 19:31:03 2018 +0200
@@ -474,8 +474,9 @@
     return total_consumed;
 }
 
-SyncTagFilter* parse_tagfilter_string(const char* filterstring) {
+SyncTagFilter* parse_tagfilter_string(const char* filterstring, int scope) {
     SyncTagFilter* tagfilter = calloc(1, sizeof(SyncTagFilter));
+    tagfilter->scope = scope;
     if (!filterstring) {
         return tagfilter;
     }
--- a/dav/tags.h	Sun Jun 10 13:24:30 2018 +0200
+++ b/dav/tags.h	Mon Jun 11 19:31:03 2018 +0200
@@ -47,6 +47,9 @@
 #define DAV_SYNC_TAGFILTER_ONE     3
 #define DAV_SYNC_TAGFILTER_NONE    4
     
+#define DAV_SYNC_TAGFILTER_SCOPE_RESOURCE   1
+#define DAV_SYNC_TAGFILTER_SCOPE_COLLECTION 2
+    
 typedef struct DavTag {
     char *name;
     char *color;
@@ -60,6 +63,7 @@
 typedef struct SyncTagFilter SyncTagFilter;
 
 struct SyncTagFilter {
+    int scope;
     int mode;
     UcxList* tags;
     size_t subfilter_count;
@@ -85,7 +89,7 @@
 
 /* ----------- ----------- tag filter  ---------------------- */
 
-SyncTagFilter* parse_tagfilter_string(const char* filterstring);
+SyncTagFilter* parse_tagfilter_string(const char* filterstring, int scope);
 void free_tagfilter(SyncTagFilter* filter);
 
 int matches_tagfilter(UcxList *dav_tags, SyncTagFilter *tagfilter);

mercurial