disables tagfilter for directories

Wed, 13 Jun 2018 16:57:56 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 13 Jun 2018 16:57:56 +0200
changeset 417
f340460a8b5d
parent 416
d7a086201a6e
child 418
cfdeeed64ac5

disables tagfilter for directories

dav/scfg.c file | annotate | diff | comparison | revisions
dav/scfg.h file | annotate | diff | comparison | revisions
dav/sync.c file | annotate | diff | comparison | revisions
--- a/dav/scfg.c	Tue Jun 12 11:14:16 2018 +0200
+++ b/dav/scfg.c	Wed Jun 13 16:57:56 2018 +0200
@@ -96,7 +96,7 @@
         xmlNode *node,
         UcxList **include,
         UcxList **exclude,
-        SyncTagFilter **tagfilter)
+        UcxList **tags)
 {
     node = node->children;
     
@@ -113,9 +113,9 @@
                 }
             } else if(xstreq(node->name, "tags")) {
                 if(value) {
-                    *tagfilter = parse_tagfilter_string(
+                    SyncTagFilter *tagfilter = parse_tagfilter_string(
                             value, DAV_SYNC_TAGFILTER_SCOPE_RESOURCE);
-                    if(!*tagfilter) {
+                    if(!tagfilter) {
                         print_error(
                                 node->line,
                                 "malformed tag filter: %s\n",
@@ -127,18 +127,23 @@
                         if(scope) {
                             if(xstreq(scope, "resource"))
                             {
-                                (*tagfilter)->scope = 
+                                tagfilter->scope = 
                                         DAV_SYNC_TAGFILTER_SCOPE_RESOURCE;
                             } else if(xstreq(scope, "collection")) {
-                                (*tagfilter)->scope = 
+                                tagfilter->scope = 
                                         DAV_SYNC_TAGFILTER_SCOPE_COLLECTION;
                             } else if(xstreq(scope, "all")) {
-                                (*tagfilter)->scope = 
+                                tagfilter->scope = 
                                         DAV_SYNC_TAGFILTER_SCOPE_RESOURCE
                                       | DAV_SYNC_TAGFILTER_SCOPE_COLLECTION;
+                            } else {
+                                tagfilter->scope =
+                                        DAV_SYNC_TAGFILTER_SCOPE_RESOURCE;
                             }
                         }
                         xmlFree(scope);
+                        
+                        *tags = ucx_list_append(*tags, tagfilter);
                     }
                 }
             } else {
@@ -257,7 +262,7 @@
     TagConfig *tagconfig = NULL;
     UcxList *include = NULL;
     UcxList *exclude = NULL;
-    SyncTagFilter *tagfilter = NULL;
+    UcxList *tagfilter = NULL;
     int max_retry = 0;
     int allow_cmd = SYNC_CMD_PULL | SYNC_CMD_PUSH | SYNC_CMD_ARCHIVE;
     bool backuppull = false;
--- a/dav/scfg.h	Tue Jun 12 11:14:16 2018 +0200
+++ b/dav/scfg.h	Wed Jun 13 16:57:56 2018 +0200
@@ -60,7 +60,7 @@
     TagConfig *tagconfig;
     UcxList *include;
     UcxList *exclude;
-    SyncTagFilter *tagfilter;
+    UcxList *tagfilter;
     int max_retry;
     int allow_cmd;
     time_t lock_timeout;
--- a/dav/sync.c	Tue Jun 12 11:14:16 2018 +0200
+++ b/dav/sync.c	Wed Jun 13 16:57:56 2018 +0200
@@ -262,10 +262,14 @@
     if(!tagfilter || tagfilter->mode == DAV_SYNC_TAGFILTER_OFF) {
         return 1;
     }
-    int scope = res->iscollection ?
-            DAV_SYNC_TAGFILTER_SCOPE_COLLECTION
-          : DAV_SYNC_TAGFILTER_SCOPE_RESOURCE;
-    if(tagfilter->scope & scope != scope) {
+    // NOTE: currently not implementable
+    //int scope = res->iscollection ?
+    //        DAV_SYNC_TAGFILTER_SCOPE_COLLECTION
+    //      : DAV_SYNC_TAGFILTER_SCOPE_RESOURCE;
+    //if((tagfilter->scope & scope) != scope) {
+    //    return 1;
+    //}
+    if(res->iscollection) {
         return 1;
     }
     
@@ -288,10 +292,13 @@
     if(!tagfilter || tagfilter->mode == DAV_SYNC_TAGFILTER_OFF) {
         return 1;
     }
-    int scope = res->isdirectory ?
-            DAV_SYNC_TAGFILTER_SCOPE_COLLECTION
-          : DAV_SYNC_TAGFILTER_SCOPE_RESOURCE;
-    if(tagfilter->scope & scope != scope) {
+    //int scope = res->isdirectory ?
+    //        DAV_SYNC_TAGFILTER_SCOPE_COLLECTION
+    //      : DAV_SYNC_TAGFILTER_SCOPE_RESOURCE;
+    //if((tagfilter->scope & scope) != scope) {
+    //    return 1;
+    //}
+    if(res->isdirectory) {
         return 1;
     }
 
@@ -482,9 +489,19 @@
         stack = ucx_list_remove(stack, stack);
          
         while(res) {
-            if (   res_matches_filter(dir, res->path)
-                || !res_matches_tags(res, dir->tagfilter))
-            {
+            DavBool res_filtered = FALSE;
+            if (res_matches_filter(dir, res->path)) {
+                res_filtered = TRUE;
+            } else {
+                UCX_FOREACH(elm, dir->tagfilter) {
+                    SyncTagFilter *tf = elm->data;
+                    if(!res_matches_tags(res, tf)) {
+                        res_filtered = TRUE;
+                        break;
+                    }
+                }
+            }
+            if(res_filtered) {
                 // don't delete files filtered by config
                 localres_keep(db, res->path);
                 res = res->next;
@@ -1026,9 +1043,19 @@
         LocalResource *local_res = elm->data;
         int error = 0;
         
-        if (   res_matches_filter(dir, local_res->path+1)
-            || !localres_matches_tags(dir, local_res, dir->tagfilter))
-        {
+        DavBool res_filtered = FALSE;
+        if(res_matches_filter(dir, local_res->path+1)) {
+            res_filtered = TRUE;
+        } else {
+            UCX_FOREACH(elm, dir->tagfilter) {
+                SyncTagFilter *tf = elm->data;
+                if(!localres_matches_tags(dir, local_res, tf)) {
+                    res_filtered = TRUE;
+                    break;
+                }
+            }
+        }
+        if (res_filtered) {
             local_res->keep = TRUE;
         } else if (!localres_matches_tags(dir, local_res, tagfilter)) {
             if(!remove_file) {
@@ -1137,7 +1164,7 @@
         UcxMapIterator i = ucx_map_iterator(db->resources);
         LocalResource *local;
         UCX_MAP_FOREACH(key, local, i) {
-            if (!local->keep) {
+            if (!local->keep && !res_matches_filter(dir, local->path+1)) {
                 if(sync_shutdown) {
                     ucx_map_cstr_put(lclres, local->path, local_resource_copy(local));
                 } else if(sync_delete_remote_resource(sn, local, &sync_delete)) {

mercurial