Wed, 20 Mar 2019 10:23:39 +0100
implements list-versions for deltav syncdirs
dav/sync.c | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Wed Mar 20 09:27:29 2019 +0100 +++ b/dav/sync.c Wed Mar 20 10:23:39 2019 +0100 @@ -3033,6 +3033,22 @@ return str; } +void print_resource_version(DavResource *res, char *name) { + time_t now = res->lastmodified; + struct tm *date = gmtime(&now); + char str[32]; + putenv("LC_TIME=C"); + size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT", date); + + printf("name: %s\n", name); + printf("lastmodified: %s\n", str); + char *server = util_url_base(res->session->base_url); + char *url = util_concat_path(server, res->href); + printf("url: %s\n", url); + free(server); + free(url); +} + int cmd_list_versions(CmdArgs *a) { if(a->argc != 1) { fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many"); @@ -3114,26 +3130,27 @@ DavBool first = 1; UCX_FOREACH(elm, children) { DavResource *c = elm->data; - time_t now = c->lastmodified; - struct tm *date = gmtime(&now); - char str[32]; - putenv("LC_TIME=C"); - size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT", date); - if(!first) { putchar('\n'); } - printf("name: %s\n", c->name); - printf("lastmodified: %s\n", str); - char *server = util_url_base(sn->base_url); - char *url = util_concat_path(server, c->href); - printf("url: %s\n", url); - free(server); - free(url); + print_resource_version(c, c->name); first = 0; } ucx_list_free(children); } while(0); + } else if(dir->versioning->type == VERSIONING_DELTAV) { + DavResource *versions = dav_versiontree(res, NULL); + DavResource *v = versions; + DavBool first = 1; + while(v) { + if(!first) { + putchar('\n'); + } + char *vname = dav_get_string_property(v, "D:version-name"); + print_resource_version(v, vname); + first = 0; + v = v->next; + } } free(file.path); @@ -3417,8 +3434,30 @@ } // TODO: normalize path + DavBool not_in_dir = 0; - if(!sstrprefix(sstr((char*)fullpath), sstr(dir->path))) { + scstr_t fp = scstr(fullpath); + scstr_t dp = scstr(dir->path); + if(fp.length == dp.length) { + if(sstrcmp(fp, dp)) { + not_in_dir = 1; + } + } else if(fp.length < dp.length) { + not_in_dir = 1; + } else { + if(!sstrprefix(fp, dp)) { + not_in_dir = 1; + } else { + if(dp.ptr[dp.length-1] == '/') { + dp.length--; + } + if(fp.ptr[dp.length] != '/') { + not_in_dir = 1; + } + } + } + + if(not_in_dir) { free(fullpath); return 0; } @@ -3483,8 +3522,8 @@ case 1: fprintf(stderr, "File %s: not found\n", path); break; case 2: fprintf(stderr, "File %s: permission denied\n"); break; case 3: fprintf(stderr, "File %s: stat failed: %s\n", path, strerror(errno)); break; - case 4: fprintf(stderr, "File %s is not in any syncdir\n"); break; - case 5: fprintf(stderr, "File %s is in multiple syncdirs\n"); break; + case 4: fprintf(stderr, "File %s is not in any syncdir\n", path); break; + case 5: fprintf(stderr, "File %s is in multiple syncdirs\n", path); break; case 6: fprintf(stderr, "Syncdir not found\n"); break; } }