changed max-retry meaning and filter configuration in sync.xml

Wed, 13 Jul 2016 14:29:50 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 13 Jul 2016 14:29:50 +0200
changeset 244
47791bdf1725
parent 243
f5921d151c29
child 246
470f0c2e505e

changed max-retry meaning and filter configuration in sync.xml

prior to this change, max-retry was the number of trials. Now it is exactly the number of retries.

include and exclude filters are now surrounded by an filter element in sync.xml

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	Wed Jul 13 12:03:04 2016 +0200
+++ b/dav/scfg.c	Wed Jul 13 14:29:50 2016 +0200
@@ -120,6 +120,27 @@
     }
 }
 
+static int scfg_load_filter(xmlNode *node, UcxList **include, UcxList **exclude) {
+    node = node->children;
+    
+    while(node) {
+        if(node->type == XML_ELEMENT_NODE) {
+            char *value = util_xml_get_text(node);
+            if(!value) {
+                return 1;
+            } else if(xstreq(node->name, "include")) {
+                *include = add_regex_pattern(*include, value);
+            } else if(xstreq(node->name, "exclude")) {
+                *exclude = add_regex_pattern(*exclude, value);
+            }
+        }
+        
+        node = node->next;
+    }
+    
+    return 0;
+}
+
 int scfg_load_directory(xmlNode *node) {
     char *name = NULL;
     char *path = NULL;
@@ -129,7 +150,7 @@
     char *database = NULL;
     UcxList *include = NULL;
     UcxList *exclude = NULL;
-    int max_retry = DAV_MAX_RETRY;
+    int max_retry = 0;
     bool backuppull = false;
     bool lockpull = false;
     bool lockpush = false;
@@ -150,18 +171,18 @@
                 collection = value;
             } else if(xstreq(node->name, "repository")) {
                 repository = value;
+            } else if(xstreq(node->name, "filter")) {
+                if(scfg_load_filter(node, &include, &exclude)) {
+                    return -1;
+                }
             } else if(xstreq(node->name, "database")) {
                 database = value;
-            } else if(xstreq(node->name, "include")) {
-                include = add_regex_pattern(include, value);
-            } else if(xstreq(node->name, "exclude")) {
-                exclude = add_regex_pattern(exclude, value);
             } else if(xstreq(node->name, "max-retry")) {
                 int64_t i;
-                if(util_strtoint(value, &i)) {
+                if(util_strtoint(value, &i) && i >= 0) {
                     max_retry = (int)i;
                 } else {
-                    fprintf(stderr, "Warnung: sync.xml: integer value "
+                    fprintf(stderr, "Warnung: sync.xml: unsigned integer value "
                                     "expected in <max-retry> element\n");
                 }
             } else if(xstreq(node->name, "backup-on-pull")) {
--- a/dav/scfg.h	Wed Jul 13 12:03:04 2016 +0200
+++ b/dav/scfg.h	Wed Jul 13 14:29:50 2016 +0200
@@ -38,7 +38,6 @@
 extern "C" {
 #endif
 
-#define DAV_MAX_RETRY 1
     
 typedef struct SyncDirectory {
     char *name;
--- a/dav/sync.c	Wed Jul 13 12:03:04 2016 +0200
+++ b/dav/sync.c	Wed Jul 13 14:29:50 2016 +0200
@@ -1099,7 +1099,7 @@
     
     int ret = -1;
     int created = 0;
-    for(int i=0;i<dir->max_retry;i++) {
+    for(int i=0;i<=dir->max_retry;i++) {
         if(!created && dav_create(res)) {
             continue;
         }
@@ -1166,7 +1166,7 @@
 int sync_mkdir(SyncDirectory *dir, DavResource *res, LocalResource *local) {
     res->iscollection = 1;
     int ret = -1;
-    for(int i=0;i<dir->max_retry;i++) {
+    for(int i=0;i<=dir->max_retry;i++) {
         if(dav_create(res)) {
             continue;
         }

mercurial