# HG changeset patch # User Olaf Wintermann # Date 1552485940 -3600 # Node ID c5bbae4b3ccadd95ca5a7520890d6bbf883c8caf # Parent da2b0cc44e4fc6fa4794fb711875c19aa58db787 extends sync db diff -r da2b0cc44e4f -r c5bbae4b3cca dav/db.c --- 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 #include #include +#include #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); diff -r da2b0cc44e4f -r c5bbae4b3cca dav/db.h --- 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 #include #include #include @@ -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); diff -r da2b0cc44e4f -r c5bbae4b3cca dav/scfg.c --- 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; diff -r da2b0cc44e4f -r c5bbae4b3cca dav/scfg.h --- 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; diff -r da2b0cc44e4f -r c5bbae4b3cca dav/sync.c --- 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; }