dav/db.c

changeset 552
e1a12762bf0a
parent 550
8c700eae3eb8
child 560
a816e805e5db
--- a/dav/db.c	Sun Apr 07 10:44:29 2019 +0200
+++ b/dav/db.c	Sun Apr 07 13:08:50 2019 +0200
@@ -654,6 +654,64 @@
     free(res);
 }
 
+char* nullstrdup(const char *s) {
+    return s ? strdup(s) : NULL;
+}
+
+LocalResource* local_resource_copy(LocalResource *src, const char *new_path) {
+    LocalResource *newres = calloc(1, sizeof(LocalResource));
+    newres->path = strdup(new_path);
+    newres->etag = nullstrdup(src->etag);
+    newres->hash = nullstrdup(src->hash);
+    newres->last_modified = src->last_modified;
+    newres->mode = src->mode;
+    newres->uid = src->uid;
+    newres->gid = src->gid;
+    newres->size = src->size;
+    newres->isdirectory = src->isdirectory;
+    newres->skipped = src->skipped;
+    
+    if(src->xattr) {
+        XAttributes *xattr = calloc(1, sizeof(XAttributes));
+        xattr->hash = nullstrdup(src->xattr->hash);
+        xattr->nattr = src->xattr->nattr;
+        xattr->names = calloc(xattr->nattr, sizeof(char*));
+        xattr->values = calloc(xattr->nattr, sizeof(sstr_t));
+        for(int i=0;i<xattr->nattr;i++) {
+            xattr->names[i] = strdup(src->xattr->names[i]);
+            xattr->values[i] = sstrdup(src->xattr->values[i]);
+        }
+        newres->xattr = xattr;
+    }
+    
+    newres->tags_hash = nullstrdup(src->tags_hash);
+    newres->xattr_hash = nullstrdup(src->xattr_hash);
+    newres->remote_tags_hash = nullstrdup(src->remote_tags_hash);
+    
+    if(src->parts) {
+        newres->numparts = src->numparts;
+        newres->parts = calloc(src->numparts, sizeof(FilePart));
+        for(int i=0;i<newres->numparts;i++) {
+            FilePart s = src->parts[i];
+            FilePart p;
+            p.block = s.block;
+            p.hash = nullstrdup(s.hash);
+            p.etag = nullstrdup(s.etag);
+            newres->parts[i] = p;
+        }
+    }
+    
+    newres->blocksize = src->blocksize;
+    
+    newres->tags_updated = src->tags_updated;
+    newres->finfo_updated = src->finfo_updated;
+    newres->xattr_updated = src->xattr_updated;
+    newres->metadata_updated = src->metadata_updated;
+    
+    return newres;
+    
+}
+
 void filepart_free(FilePart *part) {
     if(part->etag) {
         free(part->etag);

mercurial