--- a/dav/sync.c Sun Aug 08 14:59:02 2021 +0200 +++ b/dav/sync.c Sun Aug 08 16:49:47 2021 +0200 @@ -249,7 +249,7 @@ ret = cmd_list_dirs(); } else if(!strcmp(cmd, "check-repos") || !strcmp(cmd, "check-repositories")) { - ret = cmd_check_repositories(); + ret = cmd_check_repositories(args); } else { print_usage(argv[0]); } @@ -447,12 +447,14 @@ return ret; } -static DavSession* create_session(DavContext *ctx, Repository *repo, char *collection) { +static DavSession* create_session(CmdArgs *a, 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); + char *url = util_concat_path(repo->url, collection); + free(repo->url); + repo->url = url; + collection = NULL; find_collection = FALSE; } if(!collection || (collection[0] == '/' && strlen(collection) == 1)) { @@ -461,14 +463,9 @@ // the base url find_collection = FALSE; } - DavSession *sn = dav_session_new_auth( - ctx, - url, - repo->user, - repo->password); - if(url != repo->url) { - free(url); - } + + DavSession *sn = connect_to_repo(ctx, repo, collection, request_auth, a); + sn->flags = flags; sn->key = dav_context_get_key(ctx, repo->default_key); curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); @@ -491,7 +488,7 @@ dav_session_set_baseurl(sn, newurl); free(newurl); } - + return sn; } @@ -596,7 +593,7 @@ hashes = create_hash_index(db); } - DavSession *sn = create_session(ctx, repo, dir->collection); + DavSession *sn = create_session(a, ctx, repo, dir->collection); ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); if (cmd_getoption(a, "verbose")) { curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); @@ -1933,7 +1930,7 @@ } remove_deleted_conflicts(dir, db); - DavSession *sn = create_session(ctx, repo, dir->collection); + DavSession *sn = create_session(a, ctx, repo, dir->collection); ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); if (cmd_getoption(a, "verbose")) { curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); @@ -2592,7 +2589,7 @@ fprintf(stderr, "Unkown repository %s\n", dir->name); return -1; } - DavSession *sn = create_session(ctx, repo, dir->collection); + DavSession *sn = create_session(a, ctx, repo, dir->collection); ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); if (cmd_getoption(a, "verbose")) { curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); @@ -5044,7 +5041,7 @@ } remove_deleted_conflicts(dir, db); - DavSession *sn = create_session(ctx, repo, dir->collection); + DavSession *sn = create_session(a, ctx, repo, dir->collection); ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db); if (cmd_getoption(a, "verbose")) { curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); @@ -5603,7 +5600,7 @@ return 0; } -int cmd_check_repositories() { +int cmd_check_repositories(CmdArgs *a) { int ret = EXIT_SUCCESS; UcxList *reponames = NULL; @@ -5623,7 +5620,7 @@ printf(" not found in config.xml!\n"); ret = EXIT_FAILURE; } else { - DavSession *sn = create_session(ctx, repo, repo->url); + DavSession *sn = create_session(a, ctx, repo, repo->url); if (sn) { DavResource *res = dav_query(sn, "select - from / with depth = 0");