--- a/dav/sync.c Tue Nov 13 23:33:59 2018 +0100 +++ b/dav/sync.c Fri Nov 16 12:46:31 2018 +0100 @@ -322,13 +322,23 @@ return ret; } -static DavSession* create_session(DavContext *ctx, Repository *repo, char *url) { +static DavSession* create_session(DavContext *ctx, Repository *repo, char *collection) { + int flags = get_repository_flags(repo); + char *url = repo->url; + DavBool find_collection = TRUE; + if((flags & DAV_SESSION_DECRYPT_NAME) != DAV_SESSION_DECRYPT_NAME) { + url = util_concat_path(repo->url, collection); + find_collection = FALSE; + } DavSession *sn = dav_session_new_auth( ctx, url, repo->user, repo->password); - sn->flags = get_repository_flags(repo); + if(url != repo->url) { + free(url); + } + sn->flags = flags; sn->key = dav_context_get_key(ctx, repo->default_key); curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); @@ -339,6 +349,18 @@ curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0); } + + if(find_collection) { + DavResource *col = dav_resource_new(sn, collection); + dav_exists(col); // exec this to get the href + // we actually don't care what the result is + // if it doesn't exists, an error will occur later + // and we can't handle it here + char *newurl = util_concat_path(repo->url, util_resource_name(col->href)); + dav_session_set_baseurl(sn, newurl); + free(newurl); + } + return sn; } @@ -427,15 +449,8 @@ } remove_deleted_conflicts(dir, db); - char *new_url = NULL; - if(dir->collection) { - new_url = util_concat_path(repo->url, dir->collection); - } - DavSession *sn = create_session(ctx, repo, new_url ? new_url : repo->url); + DavSession *sn = create_session(ctx, repo, dir->collection); ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); - if(new_url) { - free(new_url); - } if (cmd_getoption(a, "verbose")) { curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); @@ -1019,15 +1034,8 @@ } remove_deleted_conflicts(dir, db); - char *new_url = NULL; - if(dir->collection) { - new_url = util_concat_path(repo->url, dir->collection); - } - DavSession *sn = create_session(ctx, repo, new_url ? new_url : repo->url); + DavSession *sn = create_session(ctx, repo, dir->collection); ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); - if(new_url) { - free(new_url); - } if (cmd_getoption(a, "verbose")) { curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); @@ -1364,15 +1372,8 @@ fprintf(stderr, "Unkown repository %s\n", dir->name); return -1; } - char *new_url = NULL; - if(dir->collection) { - new_url = util_concat_path(repo->url, dir->collection); - } - DavSession *sn = create_session(ctx, repo, new_url ? new_url : repo->url); + DavSession *sn = create_session(ctx, repo, dir->collection); ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); - if(new_url) { - free(new_url); - } if (cmd_getoption(a, "verbose")) { curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr);