exclude tag xattr from xattribute sync

Sat, 10 Aug 2019 21:32:07 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 10 Aug 2019 21:32:07 +0200
changeset 618
4b34d12cf211
parent 617
1c995e93bf40
child 619
1d20a6cab2e5

exclude tag xattr from xattribute sync

dav/finfo.c file | annotate | diff | comparison | revisions
dav/finfo.h file | annotate | diff | comparison | revisions
dav/main.c file | annotate | diff | comparison | revisions
dav/sync.c file | annotate | diff | comparison | revisions
--- a/dav/finfo.c	Sat Aug 10 19:54:37 2019 +0200
+++ b/dav/finfo.c	Sat Aug 10 21:32:07 2019 +0200
@@ -138,13 +138,13 @@
     char *hash = NULL;
     
     DavXmlNode *node = xml;
-    while(node) {
+    for(;node;node=node->next) {
         if(node->type == DAV_XML_ELEMENT) {
             if(!strcmp(node->name, "hash")) {
                 hash = dav_xml_getstring(node->children);
             } else if(!strcmp(node->name, "xattr")) {
                 char *xattr_name = dav_xml_get_attr(node, "name");
-                if(xattr_name) {
+                if(xattr_name) {                 
                     names = ucx_list_append(names, strdup(xattr_name));
                     
                     char *text = dav_xml_getstring(node->children);
@@ -165,8 +165,6 @@
                 }
             }
         }
-        
-        node = node->next;
     }
     
     XAttributes *attributes = NULL;
@@ -190,7 +188,11 @@
     return attributes;
 }
 
-XAttributes* file_get_attributes(const char *path) {
+XAttributes* file_get_attributes(
+        const char *path,
+        xattr_filter_func filter,
+        void *filterdata)
+{
     ssize_t nelm = 0;
     char **attributes = xattr_list(path, &nelm);
     if(nelm <= 0) {
@@ -206,6 +208,14 @@
     
     size_t nattr = 0;
     for(int i=0;i<nelm;i++) {
+        if(filter) {
+            // apply filter
+            if(!filter(attributes[i], filterdata)) {
+                // exclude attribute
+                continue;
+            }
+        }
+        
         ssize_t valuelen = 0;
         char *value = xattr_get(path, attributes[i], &valuelen);
         if(valuelen >= 0) {
--- a/dav/finfo.h	Sat Aug 10 19:54:37 2019 +0200
+++ b/dav/finfo.h	Sat Aug 10 21:32:07 2019 +0200
@@ -62,13 +62,18 @@
     DavBool gid_set;
 } FileInfo;
 
+typedef int(*xattr_filter_func)(const char*,void*);
+
 uint32_t parse_finfo_settings(const char *str, char **unknown);
     
 int resource_set_finfo(const char *path, DavResource *res, uint32_t finfo);
 int resource_set_finfo_s(struct stat *s, DavResource *res, uint32_t finfo);
 
 XAttributes* xml_get_attributes(DavXmlNode *xml);
-XAttributes* file_get_attributes(const char *path);
+XAttributes* file_get_attributes(
+        const char *path,
+        xattr_filter_func filter,
+        void *filterdata);
 int resource_set_xattr(DavResource *res, XAttributes *xattr);
 void xattributes_free(XAttributes *xattr);
 
--- a/dav/main.c	Sat Aug 10 19:54:37 2019 +0200
+++ b/dav/main.c	Sat Aug 10 21:32:07 2019 +0200
@@ -1528,7 +1528,7 @@
         fprintf(stderr, "Cannot set finfo: %s.\n", strerror(errno));
     }
     if((finfo & FINFO_XATTR) == FINFO_XATTR) {
-        XAttributes *xattr = file_get_attributes(fpath);
+        XAttributes *xattr = file_get_attributes(fpath, NULL, NULL);
         if(xattr) {
             resource_set_xattr(res, xattr);
         }
--- a/dav/sync.c	Sat Aug 10 19:54:37 2019 +0200
+++ b/dav/sync.c	Sat Aug 10 21:32:07 2019 +0200
@@ -459,7 +459,18 @@
     if(local) {
         local->keep = TRUE;
     }
-    
+}
+
+static int xattr_filter(const char *name, SyncDirectory *dir) {
+    // exclude tag xattr
+    if(
+        dir->tagconfig &&
+        dir->tagconfig->store == TAG_STORE_XATTR &&
+        !strcmp(dir->tagconfig->xattr_name, name))
+    {
+        return 0;
+    }
+    return 1;
 }
 
 void res2map(DavResource *root, UcxMap *map) {
@@ -2731,7 +2742,7 @@
         
         if((dir->metadata & FINFO_XATTR) == FINFO_XATTR) {
             char *path = create_local_path(dir, local_resource_path(db_res));
-            XAttributes *xattr = file_get_attributes(path);
+            XAttributes *xattr = file_get_attributes(path, (xattr_filter_func)xattr_filter, dir);
             // test if xattr are added, removed or changed
             if((db_res->xattr_hash && !xattr) ||
                (!db_res->xattr_hash && xattr) ||
@@ -2825,7 +2836,7 @@
     // currently only xattr needed
     if((dir->metadata & FINFO_XATTR) == FINFO_XATTR) {
         char *path = create_local_path(dir, local_resource_path(res));
-        XAttributes *xattr = file_get_attributes(path);
+        XAttributes *xattr = file_get_attributes(path, (xattr_filter_func)xattr_filter, dir);
         res->xattr = xattr;
         free(path);
     }
@@ -3184,7 +3195,7 @@
         }
     }
     
-    if(!ret) {
+    if(!ret && local) {
         local->tags_updated = 0;
     }
     
@@ -3247,7 +3258,7 @@
             } else {
                 if(changed) *changed = TRUE;
             }
-            if(!newhash) {
+            if(newhash) {
                 *newhash = new_hash;
             } else {
                 free(newhash);

mercurial