# HG changeset patch # User Olaf Wintermann # Date 1505132246 -7200 # Node ID a4d3ff32d49c034d08918e0c4bcc0634366d31ac # Parent 395763c0ee69a3c0827bd8e50590c8e936d16429 adds dav remove-property command diff -r 395763c0ee69 -r a4d3ff32d49c dav/main.c --- a/dav/main.c Sun Sep 10 10:23:25 2017 +0200 +++ b/dav/main.c Mon Sep 11 14:17:26 2017 +0200 @@ -124,6 +124,8 @@ ret = cmd_set_property(args); } else if(!strcasecmp(cmd, "get-property")) { ret = cmd_get_property(args); + } else if(!strcasecmp(cmd, "remove-property")) { + ret = cmd_remove_property(args); } else if(!strcasecmp(cmd, "lock")) { ret = cmd_lock(args); } else if(!strcasecmp(cmd, "unlock")) { @@ -1248,6 +1250,51 @@ return ret; } +int cmd_remove_property(CmdArgs *a) { + if(a->argc < 2) { + fprintf(stderr, "Too few arguments\n"); + return -1; + } + + char *url = a->argv[0]; + char *path = NULL; + Repository *repo = url2repo(url, &path); + DavSession *sn = connect_to_repo(repo, a); + + if(set_session_config(sn, a)) { + return -1; + } + + char *namespace = cmd_getoption(a, "namespace"); + char *property = a->argv[1]; + + DavPropName propname; + if(namespace) { + propname.ns = namespace; + propname.name = property; + } else { + dav_get_property_namespace_str(ctx, property, &propname.ns, &propname.name); + } + + int ret = 0; + DavResource *res = dav_resource_new(sn, path); + dav_remove_property_ns(res, propname.ns, propname.name); + for(int i=0;i<2;i++) { + if(dav_store(res)) { + if(i == 0 && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn, a)) { + continue; + } + print_resource_error(sn, res->path); + fprintf(stderr, "Cannot set property.\n"); + ret = -1; + } + break; + } + + free(path); + return ret; +} + int cmd_lock(CmdArgs *a) { if(a->argc != 1) { fprintf(stderr, "Too %s arguments\n", a->argc > 1 ? "many" : "few"); diff -r 395763c0ee69 -r a4d3ff32d49c dav/main.h --- a/dav/main.h Sun Sep 10 10:23:25 2017 +0200 +++ b/dav/main.h Mon Sep 11 14:17:26 2017 +0200 @@ -63,6 +63,7 @@ int cmd_get_property(CmdArgs *args); int cmd_set_property(CmdArgs *args); +int cmd_remove_property(CmdArgs *args); int cmd_lock(CmdArgs *args); int cmd_unlock(CmdArgs *args);