Wed, 20 Mar 2019 13:20:38 +0100
fixes dav_copy_node and improves dav-sync restore
dav/sync.c | file | annotate | diff | comparison | revisions | |
libidav/xml.c | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Wed Mar 20 10:23:39 2019 +0100 +++ b/dav/sync.c Wed Mar 20 13:20:38 2019 +0100 @@ -79,7 +79,7 @@ if(!s1 && s2) { return -1; } - if(s1 && s2) { + if(s1 && !s2) { return 1; } if(!s1 && !s2) { @@ -1605,6 +1605,9 @@ UCX_MAP_FOREACH(key, resource, i) { if(resource == &nres) { resource = ucx_map_get(db->resources, key); + if(!resource) { + continue; + } } char *file_path = util_concat_path(dir->path, resource->path); @@ -1618,10 +1621,14 @@ fprintf(stderr, "Cannot stat file: %s\n", file_path); perror(""); } - } else if(!resource->isdirectory && !S_ISDIR(s.st_mode)) { - if(resource->last_modified != s.st_mtime || resource->size != s.st_size) { - if(restore_modified) { - modified = ucx_list_prepend(modified, resource); + } else { + if(files) { + modified = ucx_list_prepend(modified, resource); + } else if(!resource->isdirectory && !S_ISDIR(s.st_mode)) { + if(resource->last_modified != s.st_mtime || resource->size != s.st_size) { + if(restore_modified) { + modified = ucx_list_prepend(modified, resource); + } } } } @@ -1678,16 +1685,32 @@ LocalResource *resource = elm->data; DavResource *res = dav_get(sn, resource->path, "D:getetag,idav:status,idav:finfo,idav:xattributes"); - + if(!res) { + printf("skip: %s\n", resource->path); + continue; + //continue; + } char *status = dav_get_string_property(res, "idav:status"); if(status && !strcmp(status, "broken")) { continue; } // download the resource - if(!sync_shutdown && sync_get_resource(a, dir, res, db, &sync_success)) { - fprintf(stderr, "sync_get_resource failed for resource: %s\n", res->path); - sync_error++; + if(!sync_shutdown) { + if(resource->isdirectory) { + char *local_path = util_concat_path(dir->path, res->path); + if(sys_mkdir(local_path) && errno != EEXIST) { + fprintf(stderr, + "Cannot create directory %s: %s", + local_path, strerror(errno)); + } + free(local_path); + } else { + if(sync_get_resource(a, dir, res, db, &sync_success)) { + fprintf(stderr, "sync_get_resource failed for resource: %s\n", res->path); + sync_error++; + } + } } }
--- a/libidav/xml.c Wed Mar 20 10:23:39 2019 +0100 +++ b/libidav/xml.c Wed Mar 20 13:20:38 2019 +0100 @@ -251,7 +251,26 @@ } - +DavXmlAttr* dav_copy_xml_attr(DavXmlAttr *attr) { + if(!attr) { + return NULL; + } + DavXmlAttr *newattr = NULL; + DavXmlAttr *prev = NULL; + while(attr) { + DavXmlAttr *n = calloc(1, sizeof(DavXmlAttr)); + n->name = strdup(attr->name); + n->value = strdup(attr->value); + if(prev) { + prev->next = n; + } else { + newattr = n; + } + prev = n; + attr = attr->next; + } + return newattr; +} DavXmlNode* dav_copy_node(DavXmlNode *node) { DavXmlNode *ret = NULL; @@ -263,6 +282,7 @@ copy->namespace = strdup(node->namespace); copy->name = strdup(node->name); copy->children = dav_copy_node(node->children); + copy->attributes = dav_copy_xml_attr(node->attributes); } else { copy->contentlength = node->contentlength; copy->content = malloc(node->contentlength+1);