dav/sync.c

changeset 578
bb1e60fada74
parent 577
f49964cf7228
child 579
c80d5730c00b
--- a/dav/sync.c	Sat Apr 20 17:47:40 2019 +0200
+++ b/dav/sync.c	Sat Apr 20 18:46:00 2019 +0200
@@ -552,7 +552,7 @@
     }
     
     int ret = 0;
-    DavResource *ls = dav_query(sn, "select D:getetag,idav:status,idav:tags,idav:finfo,idav:xattributes,idav:split,`idav:content-hash` from / with depth = infinity");
+    DavResource *ls = dav_query(sn, "select D:getetag,idav:status,idav:tags,idav:finfo,idav:xattributes,idav:split,idav:link,`idav:content-hash` from / with depth = infinity");
     if(!ls) {
         print_resource_error(sn, "/");
         if(locked) {
@@ -738,6 +738,10 @@
             prev = elm->prev;
             next = elm->next;
             
+            if(dav_get_property_ns(res, DAV_NS, "link")) {
+                continue;
+            }
+            
             char *hash = sync_get_content_hash(res);
             if(!hash) {
                 continue;
@@ -1268,6 +1272,8 @@
     LocalResource *local = ucx_map_cstr_get(db->resources, path);
     char *local_path = create_local_path(dir, path);
     
+    char *link = dav_get_string_property_ns(res, DAV_NS, "link");
+    
     char *etag = dav_get_string_property(res, "D:getetag");
     SYS_STAT s;
     memset(&s, 0, sizeof(SYS_STAT));
@@ -1285,7 +1291,7 @@
     UcxList *part_updates = NULL;
     uint64_t blockcount = 0;
     char *content_hash = NULL;
-    
+       
     if(res->iscollection && !issplit) {
         // why are we here?
         return 0;
@@ -1295,37 +1301,47 @@
     
     char *tmp_path = NULL;
     FILE *out = NULL;
-    if(!issplit) {
-        tmp_path = create_tmp_download_path(local_path);
-        if(!tmp_path) {
-            fprintf(stderr, "Cannot create tmp path for %s\n", local_path);
+    if(!link) {
+        if(!issplit) {
+            tmp_path = create_tmp_download_path(local_path);
+            if(!tmp_path) {
+                fprintf(stderr, "Cannot create tmp path for %s\n", local_path);
+                free(local_path);
+                return -1;
+            }
+            out = sys_fopen(tmp_path , "wb");
+        } else {
+            out = sys_fopen(local_path, "r+b");
+            if(!out && errno == ENOENT) {
+                out = sys_fopen(local_path, "wb");
+            }
+        }
+        if(!out) {
+            fprintf(stderr, "Cannot open output file: %s\n", local_path);
             free(local_path);
+            if(tmp_path) {
+                free(tmp_path);
+            }
             return -1;
         }
-        out = sys_fopen(tmp_path , "wb");
-    } else {
-        out = sys_fopen(local_path, "r+b");
-        if(!out && errno == ENOENT) {
-            out = sys_fopen(local_path, "wb");
-        }
-    }
-    if(!out) {
-        fprintf(stderr, "Cannot open output file: %s\n", local_path);
-        free(local_path);
-        if(tmp_path) {
-            free(tmp_path);
-        }
-        return -1;
     }
     
     int64_t truncate_file = -1;
-    printf("get: %s\n", path);
-    if(issplit) {
-        part_updates = sync_download_changed_parts(res, local, out, blocksize, &blockcount, &truncate_file, &ret);
+    if(!link) {
+        printf("get: %s\n", path);
+        if(issplit) {
+            part_updates = sync_download_changed_parts(res, local, out, blocksize, &blockcount, &truncate_file, &ret);
+        } else {
+            ret = dav_get_content(res, out, (dav_write_func)fwrite);
+        }
+        fclose(out);
     } else {
-        ret = dav_get_content(res, out, (dav_write_func)fwrite);
-    }
-    fclose(out);
+        printf("link: %s -> %s\n", path, link);
+        if(sys_symlink(link, local_path)) {
+            perror("symlink");
+            ret = 1;
+        }
+    }
     
     if(issplit || dir->hashing) {
         if(truncate_file >= 0) {
@@ -1380,6 +1396,13 @@
         if(local->hash) {
             free(local->hash);
         }
+        if(local->link_target) {
+            free(local->link_target);
+        }
+        
+        if(link) {
+            local->link_target = strdup(link);
+        }
         
         update_parts(local, part_updates, blockcount);
         

mercurial