fix that symlink config was not used in sync_get_resource

Sun, 21 Apr 2019 10:46:13 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 21 Apr 2019 10:46:13 +0200
changeset 581
3f9a9c80a2d2
parent 580
caf23cf7f96d
child 582
7aec3e6cab1f

fix that symlink config was not used in sync_get_resource

dav/sync.c file | annotate | diff | comparison | revisions
dav/system.h file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Sun Apr 21 09:54:47 2019 +0200
+++ b/dav/sync.c	Sun Apr 21 10:46:13 2019 +0200
@@ -1290,7 +1290,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 *link = SYNC_SYMLINK(dir) ?
+            dav_get_string_property_ns(res, DAV_NS, "link") : NULL;
     
     char *etag = dav_get_string_property(res, "D:getetag");
     SYS_STAT s;
@@ -1299,7 +1300,7 @@
     char *blocksize_str = dav_get_string_property_ns(res, DAV_NS, "split");
     uint64_t blocksize = 0;
     DavBool issplit = FALSE;
-    if(blocksize_str) {
+    if(blocksize_str && !link) {
         if(!util_strtouint(blocksize_str, &blocksize)) {
             fprintf(stderr, "Error: split property does not contain an integer.\n");
             return 1;
@@ -1361,7 +1362,7 @@
         }
     }
     
-    if(issplit || dir->hashing) {
+    if((issplit || dir->hashing) && !link) {
         if(truncate_file >= 0) {
             // only true if issplit is true
             if(truncate(local_path, truncate_file)) {
@@ -1410,21 +1411,28 @@
 
         if(local->etag) {
             free(local->etag);
+            local->etag = NULL;
         }
         if(local->hash) {
             free(local->hash);
+            local->hash = NULL;
         }
         if(local->link_target) {
             free(local->link_target);
+            local->link_target = NULL;
         }
         
+        stat_func statfn;
         if(link) {
             local->link_target = strdup(link);
+            statfn = sys_lstat;
+        } else {
+            statfn = sys_stat;
         }
         
         update_parts(local, part_updates, blockcount);
         
-        if(sys_stat(local_path, &s)) {
+        if(statfn(local_path, &s)) {
             fprintf(stderr,
                     "Cannot stat file %s: %s\n", local_path, strerror(errno));
         }
--- a/dav/system.h	Sun Apr 21 09:54:47 2019 +0200
+++ b/dav/system.h	Sun Apr 21 10:46:13 2019 +0200
@@ -68,6 +68,8 @@
 #define SYS_STAT struct stat
 #endif
 
+typedef int(stat_func)(const char*, SYS_STAT *);
+
 void sys_freedirent(SysDirEnt *ent);
 SYS_DIR sys_opendir(const char *path);
 SysDirEnt* sys_readdir(SYS_DIR dir);

mercurial