# HG changeset patch # User Olaf Wintermann # Date 1528738263 -7200 # Node ID ea50585ec9d9796da0ac0c4f1e449dc59892a488 # Parent 241db665477a3b925e381b95f8e9e7884815ab8f adds tagfilter scope diff -r 241db665477a -r ea50585ec9d9 dav/scfg.c --- 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, diff -r 241db665477a -r ea50585ec9d9 dav/sync.c --- 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; diff -r 241db665477a -r ea50585ec9d9 dav/tags.c --- 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; } diff -r 241db665477a -r ea50585ec9d9 dav/tags.h --- 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);