moving tar option from get/put to new export/import commands

Sun, 27 May 2018 11:47:49 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 27 May 2018 11:47:49 +0200
changeset 376
222997d48ae1
parent 375
39fd327f81da
child 377
d6d7c16dd066

moving tar option from get/put to new export/import commands

dav export creates an archive from a collection
dav import uploads the content of an archive to a collection

dav/main.c file | annotate | diff | comparison | revisions
dav/main.h file | annotate | diff | comparison | revisions
dav/optparser.c file | annotate | diff | comparison | revisions
--- a/dav/main.c	Sat May 12 15:03:11 2018 +0200
+++ b/dav/main.c	Sun May 27 11:47:49 2018 +0200
@@ -105,9 +105,9 @@
         if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) {
             ret = cmd_list(args);
         } else if(!strcasecmp(cmd, "get")) {
-            ret = cmd_get(args);
+            ret = cmd_get(args, FALSE);
         } else if(!strcasecmp(cmd, "put")) {
-            ret = cmd_put(args);
+            ret = cmd_put(args, FALSE);
         } else if(
                 !strcasecmp(cmd, "remove") ||
                 !strcasecmp(cmd, "rm") ||
@@ -120,6 +120,10 @@
             ret = cmd_move(args, true);
         } else if(!strcasecmp(cmd, "move") || !strcasecmp(cmd, "mv")) {
             ret = cmd_move(args, false);
+        } else if(!strcasecmp(cmd, "export")) {
+            ret = cmd_get(args, TRUE);
+        } else if(!strcasecmp(cmd, "import")) {
+            ret = cmd_put(args, TRUE);
         } else if(!strcasecmp(cmd, "date")) {
             ret = cmd_date(args);
         } else if(!strcasecmp(cmd, "set-property")) {
@@ -159,12 +163,14 @@
 
 static char *cmdusageinfo[] = {
     "list [-altdepcR] [-u <date>] <url>",
-    "get [-pcRKA] [-o <file>] [-u <date>] <url>",
-    "put [-pcRA] [-k <key>] [-L <lock>] <url> <file>",
+    "get [-pcRK] [-o <file>] [-u <date>] <url>",
+    "put [-pcR] [-k <key>] [-L <lock>] <url> <file>",
     "mkdir [-pc] [-k <key>] [-L <lock>] <url>",
     "remove [-pc] [-L <lock>] <url>",
     "copy [-pcO] [-L <lock>] <url> <url>",
     "move [-pcO] [-L <lock>] <url> <url>",
+    "export [-pc] [-o <file>] [-u <date>] <url>",
+    "import [-pc] [-k <key>] [-L <lock>] <url> <file>",
     "get-property [-pcx] [-n <uri>] <url> <property>",
     "set-property [-pcx] [-L <lock>] [-n <uri>] <url> <property> [value]",
     "remove-property [-pc] [-n <uri>] <url> <property>",
@@ -397,7 +403,7 @@
     int newres = update_progress(res, total, now, p);
     
     time_t newts = time(NULL);
-    if(newres || (p->ts != newts)) {
+    if((p->ts != newts)) {
         fprintf(p->out, "[%s]: %" PRId64 "k/%" PRId64 "k total: %" PRId64 "M/%" PRId64 "M\n", res->name, now/1024, total/1024, p->cur/(1024*1024), p->total/(1024*1024));
         fflush(p->out);
     }
@@ -670,13 +676,16 @@
     free(getres);
 }
 
-int cmd_get(CmdArgs *a) {
+int cmd_get(CmdArgs *a, DavBool export) {
     if(a->argc != 1) {
         // TODO: change this, when get supports retrieval of multiple files
         fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many");
         fprintf(stderr, "Usage: dav %s\n", find_usage_str("get"));
         return -1;
     }
+    if(export) {
+        ucx_map_cstr_put(a->options, "recursive", "");
+    }
     
     char *url = a->argv[0];
     char *path = NULL;
@@ -741,17 +750,16 @@
      */
     char *outfile = cmd_getoption(a, "output");
     char *basepath = outfile;
-    char *tar = cmd_getoption(a, "tar");
     if(!outfile) {
         if(res->iscollection) {
             basepath = "";
         } else {
             basepath = res->name;
         }
-        if(tar) {
+        if(export) {
             outfile = "-";
         }
-    } else if(tar) {
+    } else if(export) {
         basepath = "";
     } else if(res->iscollection && !strcmp(outfile, "-")) {
         fprintf(
@@ -815,7 +823,7 @@
     int ret;
     getfunc get;
     TarOutputStream *tout = NULL;
-    if(tar) {
+    if(export) {
         get = (getfunc)resource2tar;
         FILE *tarfile = strcmp(outfile, "-") ? fopen(outfile, "wb") : stdout;
         if(!tarfile) {
@@ -834,7 +842,7 @@
             break;
         }
     }
-    if(tar) {
+    if(export) {
         // close tar stream
         if(tar_close(tout)) {
             fprintf(stderr, "tar stream broken\n");
@@ -937,13 +945,16 @@
     return tar_end_file(tar);
 }
 
-int cmd_put(CmdArgs *a) {
+int cmd_put(CmdArgs *a, DavBool import) {
     if(a->argc != 2) {
         // TODO: change, when put supports multiple files (however it should do)
         fprintf(stderr, "Too %s arguments\n", a->argc < 2 ? "few":"many");
         fprintf(stderr, "Usage: dav %s\n", find_usage_str("put"));
         return -1;
     }
+    if(import) {
+        ucx_map_cstr_put(a->options, "resursive", "");
+    }
     
     char *url = a->argv[0];
     char *file = a->argv[1];
@@ -977,10 +988,9 @@
         return -1;
     }
     
-    char *tar = cmd_getoption(a, "tar");
     
     int ret;
-    if(!tar) {
+    if(!import) {
         if(!strcmp(file, "-")) {
             FILE *in = stdin;
             ret = put_file(repo, a, sn, path, "stdin", in, 0);
--- a/dav/main.h	Sat May 12 15:03:11 2018 +0200
+++ b/dav/main.h	Sun May 27 11:47:49 2018 +0200
@@ -70,11 +70,11 @@
 void ls_print_list_elm(DavResource *res, char *parent, CmdArgs *args);
 void ls_print_elm(DavResource *res, char *parent, CmdArgs *args);
 
-int cmd_get(CmdArgs *args);
+int cmd_get(CmdArgs *args, DavBool export);
 int get_resource(Repository *repo, GetResource *res, CmdArgs *a, void *unused);
 int resource2tar(Repository *repo, GetResource *res, CmdArgs *a, TarOutputStream *tar);
 
-int cmd_put(CmdArgs *args);
+int cmd_put(CmdArgs *args, DavBool import);
 int put_entry(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *file, DavBool root);
 int put_tar(Repository *repo, CmdArgs *a, DavSession *sn, char *tarfile, char *path);
 int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len);
--- a/dav/optparser.c	Sat May 12 15:03:11 2018 +0200
+++ b/dav/optparser.c	Sun May 27 11:47:49 2018 +0200
@@ -131,10 +131,6 @@
                         ucx_map_cstr_put(a->options, "structure", NOARG);
                         break;
                     }
-                    case 'A': {
-                        ucx_map_cstr_put(a->options, "tar", NOARG);
-                        break;
-                    }
                     case 'K': {
                         ucx_map_cstr_put(a->options, "keep", NOARG);
                         break;

mercurial