dav-sync pull applies config tag filter now

Fri, 01 Jun 2018 09:23:51 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 01 Jun 2018 09:23:51 +0200
changeset 402
babdf40dd22c
parent 401
3bb3210f3e6e
child 403
8e1948eebef5

dav-sync pull applies config tag filter now

also changes, that include/exclude filters never lead to file deletion

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	Fri Jun 01 09:07:20 2018 +0200
+++ b/dav/scfg.c	Fri Jun 01 09:23:51 2018 +0200
@@ -394,6 +394,7 @@
         regcomp(matchnothing, "///", REG_NOSUB);
         dir->exclude = ucx_list_append(NULL, matchnothing);
     }
+    dir->tagfilter = tagfilter;
     
     if (trash && sstrtrim(sstr(trash)).length > 0) {
         if (trash[0] == '/' || trash[0] == '$') {
--- a/dav/scfg.h	Fri Jun 01 09:07:20 2018 +0200
+++ b/dav/scfg.h	Fri Jun 01 09:23:51 2018 +0200
@@ -60,6 +60,7 @@
     TagConfig *tagconfig;
     UcxList *include;
     UcxList *exclude;
+    SyncTagFilter *tagfilter;
     int max_retry;
     int allow_cmd;
     time_t lock_timeout;
--- a/dav/sync.c	Fri Jun 01 09:07:20 2018 +0200
+++ b/dav/sync.c	Fri Jun 01 09:23:51 2018 +0200
@@ -258,6 +258,10 @@
 }
 
 static int res_matches_tags(DavResource *res, SyncTagFilter *tagfilter) {
+    if(!tagfilter) {
+        return 1;
+    }
+    
     if(tagfilter->mode == DAV_SYNC_TAGFILTER_OFF) {
         return 1;
     }
@@ -441,6 +445,8 @@
         return -1;
     }
     
+    DavBool remove_file = cmd_getoption(a, "remove") ? 1 : 0;
+    
     int sync_success = 0;
     int sync_delete = 0;
     int sync_error = 0;
@@ -455,13 +461,17 @@
         stack = ucx_list_remove(stack, stack);
          
         while(res) {
-            if (res_matches_filter(dir, res->path)) {
+            if (   res_matches_filter(dir, res->path)
+                || !res_matches_tags(res, dir->tagfilter))
+            {
+                // don't delete files filtered by config
+                localres_keep(db, res->path);
                 res = res->next;
                 continue;
             }
-                        
+            
             if (!res_matches_tags(res, tagfilter)) {
-                if(!cmd_getoption(a, "remove")) {
+                if(!remove_file) {
                     localres_keep(db, res->path);
                 }
                 res = res->next;

mercurial