Sun, 15 Jun 2014 20:12:48 +0200
fixed etag handling
dav/sync.c | file | annotate | diff | comparison | revisions | |
libidav/webdav.c | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Sun Jun 15 16:07:11 2014 +0200 +++ b/dav/sync.c Sun Jun 15 20:12:48 2014 +0200 @@ -167,9 +167,15 @@ LocalResource *local = ucx_map_cstr_get(db, res->path); char *etag = dav_get_property(res, "D:getetag"); if(local) { - if(local->etag && !strcmp(etag, local->etag)) { - // resource is already up-to-date on the client - return 0; + if(local->etag) { + sstr_t e = sstr(etag); + if(sstrprefix(e, S("W/"))) { + e = sstrsubs(e, 2); + } + if(!strcmp(e.ptr, local->etag)) { + // resource is already up-to-date on the client + return 0; + } } } @@ -177,7 +183,7 @@ int ret = 0; if(res->iscollection) { mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; - printf("mkdir %s\n", local_path); + //printf("mkdir %s\n", local_path); if(util_mkdir(local_path, mode) && errno != EEXIST) { ret = -1; } @@ -378,9 +384,6 @@ if(dav_store(res)) { break; } - if(dav_load(res)) { - break; - } ret = 0; break; } @@ -390,9 +393,21 @@ if(local_res->etag) { free(local_res->etag); } - char *etag = dav_get_property(res, "D:getetag"); - if(etag) { - local_res->etag = strdup(dav_get_property(res, "D:getetag")); + + DavResource *up_res = dav_get(res->session, res->path, "D:getetag"); + char *etag_str = dav_get_property(up_res, "D:getetag"); + sstr_t etag; + etag.ptr = NULL; + if(etag_str) { + etag = sstr(etag_str); + } + if(sstrprefix(etag, S("W/"))) { + etag = sstrsubs(etag, 2); + } + + + if(etag.ptr) { + local_res->etag = strdup(etag.ptr); } else { local_res->etag = NULL; }
--- a/libidav/webdav.c Sun Jun 15 16:07:11 2014 +0200 +++ b/libidav/webdav.c Sun Jun 15 20:12:48 2014 +0200 @@ -160,9 +160,8 @@ DavResource* dav_get(DavSession *sn, char *path, char *properties) { CURL *handle = sn->handle; - char *href = dav_session_get_href(sn, path); - util_set_url(sn, href); - dav_session_free(sn, href); + DavResource *resource = dav_resource_new(sn, path); + util_set_url(sn, dav_resource_get_href(resource)); UcxList *proplist = NULL; if(properties) { @@ -174,16 +173,16 @@ //fwrite(rqbuf->space, 1, rqbuf->size, stdout); //printf("\n"); - DavResource *resource = NULL; CURLcode ret = do_propfind_request(handle, rqbuf, rpbuf); int status = 0; curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); if(ret == CURLE_OK && status == 207) { - //printf("response\n%s\n", rpbuf->space); - resource = parse_propfind_response(sn, NULL, rpbuf, NULL, 0); + //printf("response\n%s\n", rpbuf->space); + resource = parse_propfind_response(sn, resource, rpbuf, NULL, 0); sn->error = DAV_OK; } else { dav_session_set_error(sn, ret, status); + dav_resource_free(resource); } ucx_buffer_free(rqbuf);