Sat, 19 Mar 2016 12:34:32 +0100
fixed some bugs in dav_create() and dav-sync push
dav/sync.c | file | annotate | diff | comparison | revisions | |
libidav/methods.c | file | annotate | diff | comparison | revisions | |
libidav/methods.h | file | annotate | diff | comparison | revisions | |
libidav/resource.c | file | annotate | diff | comparison | revisions | |
libidav/webdav.c | file | annotate | diff | comparison | revisions | |
mingw.mk | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Fri Mar 18 19:54:36 2016 +0100 +++ b/dav/sync.c Sat Mar 19 12:34:32 2016 +0100 @@ -352,14 +352,14 @@ // store db if(store_db(db, dir->database)) { fprintf(stderr, "Cannot store sync db\n"); - ret = -1; + ret = -2; } - // TODO: cleanup - BUT DONT CLEANUP SYNC CONFIG (do this in main!) + // TODO: cleanup dav_session_destroy(sn); // Report - if(ret == 0) { + if(ret != -2) { char *str_success = sync_success == 1 ? "file" : "files"; char *str_delete = sync_delete == 1 ? "file" : "files"; char *str_error = sync_error == 1 ? "error" : "errors"; @@ -753,11 +753,11 @@ if(res_isconflict(db, local_res)) { printf("skip: %s\n", local_res->path); sync_skipped++; - local_resource_free(local_res); continue; } // upload every changed file + int error = 0; if (local_resource_is_changed(dir, db, local_res)) { DavResource *res = dav_resource_new(sn, local_res->path); if(!res) { @@ -777,7 +777,6 @@ if(cdt && remote_resource_is_changed(sn, dir, db, local_res)) { printf("conflict: %s\n", local_res->path); sync_skipped++; - local_resource_free(local_res); continue; } @@ -787,6 +786,7 @@ print_resource_error(sn, res->path); ret = -1; sync_error++; + error = 1; } } dav_resource_free(res); @@ -794,14 +794,17 @@ // remove every locally available resource from db->resource // the remaining elements are all deleted files - ucx_map_cstr_put(lclres, local_res->path, local_res); + elm->data = NULL; + if(!error) { + ucx_map_cstr_put(lclres, local_res->path, local_res); + } + LocalResource *lr = ucx_map_cstr_remove(db->resources, local_res->path); if(lr) { local_resource_free(lr); } } } - ucx_list_free(resources); // delete all removed files if(ret == 0) { @@ -820,6 +823,7 @@ } } } + ucx_map_free_content(db->resources, (ucx_destructor)local_resource_free); ucx_map_free(db->resources); db->resources = lclres; @@ -834,15 +838,22 @@ // store db if(store_db(db, dir->database)) { fprintf(stderr, "Cannot store sync db\n"); - ret = -1; + ret = -2; } // cleanup dav_session_destroy(sn); - ucx_list_free(resources); // content is already freed + while(resources) { + UcxList *next = resources->next; + if(resources->data) { + local_resource_free(resources->data); + } + free(resources); + resources = next; + } // Report - if(ret == 0) { + if(ret != -2) { char *str_success = sync_success == 1 ? "file" : "files"; char *str_delete = sync_delete == 1 ? "file" : "files"; char *str_skipped = sync_delete == 1 ? "file" : "files";
--- a/libidav/methods.c Fri Mar 18 19:54:36 2016 +0100 +++ b/libidav/methods.c Sat Mar 19 12:34:32 2016 +0100 @@ -846,7 +846,9 @@ s = S("</D:propertyupdate>\n"); ucx_buffer_write(s.ptr, 1, s.length, buf); - // TODO: cleanup namespace map + // cleanup namespace map + ucx_map_free_content(namespaces, free); + ucx_map_free(namespaces); return buf; } @@ -900,7 +902,7 @@ return s*n; } -CURLcode do_put_request(CURL *handle, char *lock, void *data, dav_read_func read_func, size_t length) { +CURLcode do_put_request(CURL *handle, char *lock, DavBool create, void *data, dav_read_func read_func, size_t length) { curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL); curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); @@ -909,7 +911,14 @@ if(lock) { char *url = NULL; curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); - char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; + char *ltheader = NULL; + if(create) { + url = util_parent_path(url); + ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; + free(url); + } else { + ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; + } headers = curl_slist_append(headers, ltheader); free(ltheader); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); @@ -942,6 +951,7 @@ if(buf) { ucx_buffer_free(buf); } + return ret; } @@ -974,7 +984,9 @@ if(lock) { char *url = NULL; curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); + url = util_parent_path(url); char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr; + free(url); headers = curl_slist_append(headers, ltheader); free(ltheader); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL);
--- a/libidav/methods.h Fri Mar 18 19:54:36 2016 +0100 +++ b/libidav/methods.h Sat Mar 19 12:34:32 2016 +0100 @@ -74,6 +74,7 @@ CURLcode do_put_request( CURL *handle, char *lock, + DavBool create, void *data, dav_read_func read_func, size_t length);
--- a/libidav/resource.c Fri Mar 18 19:54:36 2016 +0100 +++ b/libidav/resource.c Sat Mar 19 12:34:32 2016 +0100 @@ -583,6 +583,7 @@ ret = do_put_request( sn->handle, locktoken, + FALSE, enc, (dav_read_func)aes_read, 0); @@ -609,6 +610,7 @@ ret = do_put_request( sn->handle, locktoken, + FALSE, data->content, data->read, data->length); @@ -632,6 +634,8 @@ } // store properties + int r = 0; + sn->error = DAV_OK; if(data->set || data->remove) { UcxBuffer *request = create_proppatch_request(data); UcxBuffer *response = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND); @@ -648,11 +652,14 @@ data->remove = NULL; } else { dav_session_set_error(sn, ret, status); - return 1; + r = -1; } + + ucx_buffer_free(request); + ucx_buffer_free(response); } - sn->error = DAV_OK; - return 0; + + return r; } int dav_get_content(DavResource *res, void *stream, dav_write_func write_fnc) { @@ -757,17 +764,19 @@ CURLcode ret = do_delete_request(handle, locktoken, response); long status = 0; curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); + int r = 0; if(ret == CURLE_OK && (status >= 200 && status < 300)) { res->session->error = DAV_OK; // TODO: parse response // TODO: free res - - return 0; } else { dav_session_set_error(res->session, ret, status); - return 1; + r = 1; } + + ucx_buffer_free(response); + return r; } static int create_ancestors(DavSession *sn, char *href, char *path) { @@ -835,7 +844,7 @@ if(res->iscollection) { code = do_mkcol_request(handle, locktoken); } else { - code = do_put_request(handle, locktoken, "", NULL, 0); + code = do_put_request(handle, locktoken, TRUE, "", NULL, 0); } long s = 0; curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &s);
--- a/libidav/webdav.c Fri Mar 18 19:54:36 2016 +0100 +++ b/libidav/webdav.c Sat Mar 19 12:34:32 2016 +0100 @@ -308,6 +308,14 @@ ucx_buffer_free(rqbuf); ucx_buffer_free(rpbuf); + while(proplist) { + DavProperty *p = proplist->data; + free(p->name); + free(p); + UcxList *next = proplist->next; + free(proplist); + proplist = next; + } return resource; }