adds dav get option to keep existing files

Thu, 12 Oct 2017 20:37:46 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 12 Oct 2017 20:37:46 +0200
changeset 330
54819e984a19
parent 329
2dc61cc5a8ac
child 331
9ca1e4706acc

adds dav get option to keep existing files

dav/main.c file | annotate | diff | comparison | revisions
dav/optparser.c file | annotate | diff | comparison | revisions
dav/sync.h file | annotate | diff | comparison | revisions
dav/version.h file | annotate | diff | comparison | revisions
--- a/dav/main.c	Mon Oct 09 14:55:47 2017 +0200
+++ b/dav/main.c	Thu Oct 12 20:37:46 2017 +0200
@@ -161,7 +161,7 @@
     fprintf(stderr, "        list [-altdepcR] [-u <date>] <url>\n");
     fprintf(
             stderr,
-            "        get [-pcR] [-o <file>] [-u <date>] <url>\n");
+            "        get [-pcRK] [-o <file>] [-u <date>] <url>\n");
     fprintf(stderr, "        put [-pcR] [-k <key>] [-L <lock>] <url> <file>\n");
     fprintf(stderr, "        mkdir [-pc] [-k <key>] [-L <lock>] <url>\n");
     fprintf(stderr, "        remove [-pc] [-L <lock>] <url>\n");
@@ -189,6 +189,7 @@
     fprintf(stderr,
             "        -R         "
             "Recursively do the operation for all children\n");
+    fprintf(stderr, "        -K         Keep already present files\n");
     fprintf(stderr, "        -o <file>  Write output to file\n");
     fprintf(
             stderr,
@@ -747,12 +748,27 @@
         return 0;
     }
     
+    int isstdout = !strcmp(out, "-");
+    if(cmd_getoption(a, "keep") && !isstdout) {
+        struct stat s;
+        if(stat(out, &s)) {
+            if(errno != ENOENT) {
+                perror("stat");
+            }
+        } else {
+            if(cmd_getoption(a, "recursive")) {
+                printf("skip: %s\n", res->path);
+            }
+            return 0;
+        }
+    }
+    
     // print some status message in recursive mode
     if(cmd_getoption(a, "recursive")) {
         printf("get: %s\n", res->path);
     }
-     
-    FILE *fout = !strcmp(out, "-") ? stdout : fopen(out, "wb");
+    
+    FILE *fout = isstdout ? stdout : fopen(out, "wb");
     if(!fout) {
         fprintf(stderr, "cannot open output file\n");
         return -1;
--- a/dav/optparser.c	Mon Oct 09 14:55:47 2017 +0200
+++ b/dav/optparser.c	Thu Oct 12 20:37:46 2017 +0200
@@ -128,6 +128,10 @@
                         ucx_map_cstr_put(a->options, "structure", NOARG);
                         break;
                     }
+                    case 'K': {
+                        ucx_map_cstr_put(a->options, "keep", NOARG);
+                        break;
+                    }
                     case 'o': {
                         if(!option) {
                             option = "output";
--- a/dav/sync.h	Mon Oct 09 14:55:47 2017 +0200
+++ b/dav/sync.h	Thu Oct 12 20:37:46 2017 +0200
@@ -33,6 +33,8 @@
 #include <libidav/webdav.h>
 #include <ucx/list.h>
 
+#include <pthread.h>
+
 #include "sopt.h"
 
 #include "version.h"
--- a/dav/version.h	Mon Oct 09 14:55:47 2017 +0200
+++ b/dav/version.h	Thu Oct 12 20:37:46 2017 +0200
@@ -29,7 +29,7 @@
 #ifndef VERSION_H
 #define VERSION_H
 
-#define DAV_VERSION "1.1 RC1"
+#define DAV_VERSION "1.1 dev"
 
 #endif /* VERSION_H */
 

mercurial