dav/main.c

changeset 30
9a5a7a513a96
parent 29
938957a4eea7
child 31
59cdf7b7316f
--- a/dav/main.c	Thu Aug 22 12:45:12 2013 +0200
+++ b/dav/main.c	Thu Aug 22 14:09:26 2013 +0200
@@ -101,8 +101,10 @@
 void print_usage(char *cmd) {
     fprintf(stderr, "Usage: %s command [options] arguments...\n\n", cmd);
     fprintf(stderr, "Commands:\n");
-    fprintf(stderr, "        list [-altR] <url>\n");
-    fprintf(stderr, "        get [-pR] [-k <key>] [-o <file>] <url>\n");
+    fprintf(stderr, "list [-altR] [-u <date>] <url>\n");
+    fprintf(
+            stderr,
+            "        get [-pR] [-k <key>] [-o <file>] [-u <date>] <url>\n");
     fprintf(stderr, "        put [-p] [-k <key>] <url> <file>\n");
     fprintf(stderr, "        mkdir <url>\n");
     fprintf(stderr, "        remove <url>\n");
@@ -116,6 +118,10 @@
             "        -R         "
             "Recursively do the operation for all children\n");
     fprintf(stderr, "        -o <file>  Write output to file\n");
+    fprintf(
+            stderr,
+            "        -u <date>  "
+            "Get resources which are modified since the specified date\n");
     fprintf(stderr, "        -a         show all files\n");
     fprintf(stderr, "        -l         print resources in long list format\n");
     fprintf(stderr, "        -t         print content type\n");
@@ -214,12 +220,31 @@
         sn = dav_session_new(ctx, base);
     }
     
+    char *update = cmd_getoption(a, "update");
+    time_t t = 0;
+    if(update) {
+        t = util_parse_lastmodified(update);
+    }
+    
     DavResource *ls;
     if(cmd_getoption(a, "recursive")) {
         printf("base: %s\n", base);
-        ls = dav_query(sn, "get U:crypto-key from /*");
+        if(update) {
+            ls = dav_query(
+                    sn,
+                    "get U:crypto-key from /* where lastmodified > %t",
+                    t);
+        } else {
+            ls = dav_query(sn, "get U:crypto-key from /*");
+        }
     } else {
-        ls = dav_query(sn, "get U:crypto-key from /");
+        if(update) {
+            ls = dav_query(
+                    sn,
+                    "get U:crypto-key from / where lastmodified > %t", t);
+        } else {
+            ls = dav_query(sn, "get U:crypto-key from /");
+        }
     }
     if(!ls) {
         print_resource_error(sn, path);
@@ -418,12 +443,35 @@
         sn = dav_session_new(ctx, root);
     }
     
+    char *update = cmd_getoption(a, "update");
+    time_t t = 0;
+    if(update) {
+        t = util_parse_lastmodified(update);
+    }
+    
     int recursive = cmd_getoption(a, "recursive") ? 1 : 0;
     DavResource *res;
+    
     if(recursive) {
-        res = dav_query(sn, "get U:crypto-key from %s*", path);
+        if(update) {
+            res = dav_query(
+                    sn,
+                    "get U:crypto-key from %s* where lastmodified > %t",
+                    path,
+                    t);
+        } else {
+            res = dav_query(sn, "get U:crypto-key from %s*", path);
+        }
     } else {
-        res = dav_query(sn, "get U:crypto-key from %s", path);
+        if(update) {
+            res = dav_query(
+                    sn,
+                    "get U:crypto-key from %s where lastmodified > %t",
+                    path,
+                    t);
+        } else {
+            res = dav_query(sn, "get U:crypto-key from %s", path);
+        }
     }
     if(!res) {
         print_resource_error(sn, path);

mercurial