adds dav remove-property command

Mon, 11 Sep 2017 14:17:26 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 11 Sep 2017 14:17:26 +0200
changeset 304
a4d3ff32d49c
parent 302
395763c0ee69
child 305
c3d98b2cccf3

adds dav remove-property command

dav/main.c file | annotate | diff | comparison | revisions
dav/main.h file | annotate | diff | comparison | revisions
--- 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");
--- 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);

mercurial