extends sync db

Wed, 13 Mar 2019 15:05:40 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 13 Mar 2019 15:05:40 +0100
changeset 521
c5bbae4b3cca
parent 520
da2b0cc44e4f
child 522
46f96dcd6eab

extends sync db

dav/db.c file | annotate | diff | comparison | revisions
dav/db.h file | annotate | diff | comparison | revisions
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/db.c	Wed Mar 13 12:52:24 2019 +0100
+++ b/dav/db.c	Wed Mar 13 15:05:40 2019 +0100
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 #include "db.h"
 
@@ -124,6 +125,14 @@
                 field = 3;
             } else if(xstreq(name, "tags-hash")) {
                 field = 4;
+            } else if(xstreq(name, "mode")) {
+                field = 5;
+            } else if(xstreq(name, "uid")) {
+                field = 6;
+            } else if(xstreq(name, "gid")) {
+                field = 7;
+            } else if(xstreq(name, "xattr-hash")) {
+                field = 8;
             } else if(xstreq(name, "skipped")) {
                 res->skipped = TRUE;
             } else if(xstreq(name, "tags-updated")) {
@@ -169,6 +178,32 @@
                     res->tags_hash = strdup((char*)value);
                     break;
                 }
+                case 5: {
+                    char *end;
+                    long int mode = strtol((char*)value, &end, 8);
+                    if(errno == 0) {
+                        res->mode = (mode_t)mode;
+                    }
+                    break;
+                }
+                case 6: {
+                    uint64_t uid = 0;
+                    if(util_strtouint((char*)value, &uid)) {
+                        res->uid = (uid_t)uid;
+                    }
+                    break;
+                }
+                case 7: {
+                    uint64_t gid = 0;
+                    if(util_strtouint((char*)value, &gid)) {
+                        res->uid = (gid_t)gid;
+                    }
+                    break;
+                }
+                case 8: {
+                    res->xattr_hash = strdup((char*)value);
+                    break;
+                }
             }
         } else if(XML_READER_TYPE_END_ELEMENT) {
             if(xstreq(name, "resource")) {
@@ -219,7 +254,7 @@
     }
 }
 
-int store_db(SyncDatabase *db, char *name) {
+int store_db(SyncDatabase *db, char *name, uint32_t settings) {
     // open writer
     char *dav_dir = util_concat_path(ENV_HOME, ".dav");
     char *db_file = util_concat_path(dav_dir, name);
@@ -281,6 +316,42 @@
             return -1;
         }
         
+        if(settings & DB_STORE_MODE == DB_STORE_MODE) {
+            r = xmlTextWriterWriteFormatElement(
+                writer,
+                BAD_CAST "mode",
+                "%o",
+                (int)res->mode);
+            if(r < 0) {
+                fprintf(stderr, "Cannot write mode\n");
+                xmlFreeTextWriter(writer);
+                return -1;
+            }
+        }
+        
+        if(settings & DB_STORE_USER == DB_STORE_USER) {
+            r = xmlTextWriterWriteFormatElement(
+                    writer,
+                    BAD_CAST "uid",
+                    "%u",
+                    (unsigned int)res->uid);
+            if(r < 0) {
+                fprintf(stderr, "Cannot write uid\n");
+                xmlFreeTextWriter(writer);
+                return -1;
+            }
+            r = xmlTextWriterWriteFormatElement(
+                    writer,
+                    BAD_CAST "gid",
+                    "%u",
+                    (unsigned int)res->gid);
+            if(r < 0) {
+                fprintf(stderr, "Cannot write gid\n");
+                xmlFreeTextWriter(writer);
+                return -1;
+            }
+        }
+        
         r = xmlTextWriterWriteFormatElement(
                 writer,
                 BAD_CAST "size",
@@ -304,6 +375,18 @@
             }
         }
         
+        if(res->xattr_hash) {
+            r = xmlTextWriterWriteElement(
+                    writer,
+                    BAD_CAST "xattr-hash",
+                    BAD_CAST res->xattr_hash);
+            if(r < 0) {
+                fprintf(stderr, "Cannot write xattr-hash: %s\n", res->etag);
+                xmlFreeTextWriter(writer);
+                return -1;
+            }
+        }
+        
         if(res->skipped) {
             r = xmlTextWriterStartElement(writer, BAD_CAST "skipped");
             r += xmlTextWriterEndElement(writer);
--- a/dav/db.h	Wed Mar 13 12:52:24 2019 +0100
+++ b/dav/db.h	Wed Mar 13 15:05:40 2019 +0100
@@ -29,6 +29,7 @@
 #ifndef DB_H
 #define	DB_H
 
+#include <inttypes.h>
 #include <libidav/webdav.h>
 #include <ucx/map.h>
 #include <ucx/buffer.h>
@@ -40,6 +41,9 @@
 extern "C" {
 #endif
 
+#define DB_STORE_MODE 1
+#define DB_STORE_USER 2
+    
 typedef struct LocalResource LocalResource;   
 typedef struct SyncDatabase  SyncDatabase;
 
@@ -48,12 +52,16 @@
     char    *path;
     char    *etag;
     time_t  last_modified;
+    mode_t  mode;
+    uid_t   uid;
+    gid_t   gid;
     off_t   size;
     DavBool isdirectory;
     DavBool skipped;
     DavBool tags_updated;
     UcxBuffer *cached_tags;
     char *tags_hash;
+    char *xattr_hash;
     
     DavBool keep;
     DavBool restore;
@@ -65,7 +73,7 @@
 };
 
 SyncDatabase* load_db(char *name);
-int store_db(SyncDatabase *db, char *name);
+int store_db(SyncDatabase *db, char *name, uint32_t settings);
 void destroy_db(SyncDatabase *db);
 
 void local_resource_free(LocalResource *res);
--- a/dav/scfg.c	Wed Mar 13 12:52:24 2019 +0100
+++ b/dav/scfg.c	Wed Mar 13 15:05:40 2019 +0100
@@ -413,7 +413,7 @@
         return 1;
     }
     
-    SyncDirectory *dir = malloc(sizeof(SyncDirectory));
+    SyncDirectory *dir = calloc(1, sizeof(SyncDirectory));
     dir->name = strdup(name);
     dir->path = scfg_create_path(path);
     dir->collection = collection ? strdup(collection) : NULL;
--- a/dav/scfg.h	Wed Mar 13 12:52:24 2019 +0100
+++ b/dav/scfg.h	Wed Mar 13 15:05:40 2019 +0100
@@ -70,6 +70,7 @@
     bool backuppull;
     bool lockpull;
     bool lockpush;
+    uint32_t db_settings;
 } SyncDirectory;
 
 
--- a/dav/sync.c	Wed Mar 13 12:52:24 2019 +0100
+++ b/dav/sync.c	Wed Mar 13 15:05:40 2019 +0100
@@ -733,7 +733,7 @@
     }
     
     // store db
-    if(store_db(db, dir->database)) {
+    if(store_db(db, dir->database, dir->db_settings)) {
         fprintf(stderr, "Cannot store sync db\n");
         ret = -2;
     }
@@ -1394,7 +1394,7 @@
     }
     
     // store db
-    if(store_db(db, dir->database)) {
+    if(store_db(db, dir->database, dir->db_settings)) {
         fprintf(stderr, "Cannot store sync db\n");
         ret = -2;
     }
@@ -1549,7 +1549,7 @@
     }
     
     // store db
-    if(store_db(db, dir->database)) {
+    if(store_db(db, dir->database, dir->db_settings)) {
         fprintf(stderr, "Cannot store sync db\n");
         ret = -2;
     }
@@ -2548,7 +2548,7 @@
     ucx_map_clear(db->conflict);
     
     // store db
-    if(store_db(db, dir->database)) {
+    if(store_db(db, dir->database, dir->db_settings)) {
         fprintf(stderr, "Cannot store sync db\n");
         fprintf(stderr, "Abort\n");
         ret = -2;
@@ -2614,7 +2614,7 @@
     ucx_map_clear(db->conflict);
     
     // store db
-    if(store_db(db, dir->database)) {
+    if(store_db(db, dir->database, dir->db_settings)) {
         fprintf(stderr, "Cannot store sync db\n");
         fprintf(stderr, "Abort\n");
         ret = -1;
@@ -2939,7 +2939,7 @@
     }
     
     // store db
-    if(store_db(db, file.dir->database)) {
+    if(store_db(db, file.dir->database, file.dir->db_settings)) {
         fprintf(stderr, "Cannot store sync db\n");
         ret = -2;
     }

mercurial