]> arthur.barton.de Git - netatalk.git/commitdiff
Some work on ad cp
authorFrank Lahm <franklahm@googlemail.com>
Fri, 1 Oct 2010 22:27:51 +0000 (00:27 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Fri, 1 Oct 2010 22:27:51 +0000 (00:27 +0200)
bin/cnid/ad.c
bin/cnid/ad.h
bin/cnid/ad_cp.c
bin/cnid/ad_util.c

index 95faece79ed4a070bfb7c53b31b144f62c6ba4de..01941ce17c713d48d7716e067e0a8a93cc382985 100644 (file)
@@ -1,6 +1,4 @@
 /* 
-   $Id: ad.c,v 1.2 2009-10-13 22:55:36 didg Exp $
-
    Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
@@ -42,6 +40,8 @@ static void usage_main(void)
 
 int main(int argc, char **argv)
 {
+    setuplog("default log_info /dev/tty");
+
     if (argc < 2) {
         usage_main();
         return 1;
index bb08085676b9d332a57d810091d6d14416d5aa9d..14cc874dbd18a06178fb448688204133d65cb569 100644 (file)
@@ -1,6 +1,4 @@
 /* 
-   $Id: ad.h,v 1.1 2009-09-01 14:28:07 franklahm Exp $
-
    Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
index 938ce1b41ab267ba41cab7d6c45929fa8eb67271..531354788481b9b06eb67358705447fdc83c446d 100644 (file)
 #include <atalk/cnid.h>
 #include <atalk/volinfo.h>
 #include <atalk/util.h>
+#include <atalk/errchk.h>
+#include <atalk/bstrlib.h>
+#include <atalk/bstradd.h>
+#include <atalk/logger.h>
 #include "ad.h"
 
 #define ADv2_DIRNAME ".AppleDouble"
@@ -79,8 +83,11 @@ static void usage_cp(void)
         );
 }
 
-static int ad_cp_copy(const afpvol_t *srcvol, const afpvol_t *dstvol,
-                      char *srcfile, char *dstfile, struct stat *st)
+static int ad_cp_copy(const afpvol_t *srcvol,
+                      const afpvol_t *dstvol,
+                      char *srcfile,
+                      char *dstfile,
+                      struct stat *st)
 {
     printf("copy: '%s' -> '%s'\n", srcfile, dstfile);
     return 0;
@@ -176,6 +183,7 @@ exit:
 
 int ad_cp(int argc, char **argv)
 {
+    EC_INIT;
     int c, numpaths;
     afpvol_t srcvvol;
     struct stat sst;
@@ -184,7 +192,7 @@ int ad_cp(int argc, char **argv)
     afpvol_t dstvol;
     char *srcfile = NULL;
     char *srcdir = NULL;    
-    char *dstfile = NULL;
+    bstring dstfile;
     char *dstdir = NULL;
     char path[MAXPATHLEN+1];
     char *basenametmp;
@@ -227,19 +235,38 @@ int ad_cp(int argc, char **argv)
 
     while ( argv[argc-1][(strlen(argv[argc-1]) - 1)] == '/')
         argv[argc-1][(strlen(argv[argc-1]) - 1)] = 0;
-    printf("Destination is: %s\n", argv[argc-1]);
 
     /* Create vol for destination */
     newvol(argv[argc-1], &dstvol);
 
     if (numpaths == 2) {
         /* Case 1: 2 paths */
-        if (stat(argv[optind], &sst) != 0)
-            goto next;
+
+        /* stat source */
+        EC_ZERO(stat(argv[optind], &sst));
+
         if (S_ISREG(sst.st_mode)) {
+            /* source is just a file, thats easy */
             /* Either file to file or file to dir copy */
+
+            /* stat destination */
+            if (stat(argv[argc-1], &dst) == 0) {
+                if (S_ISDIR(dst.st_mode)) {
+                    /* its a dir, build dest path: "dest" + "/" + basename("source") */
+                    EC_NULL(dstfile = bfromcstr(argv[argc-1]));
+                    EC_ZERO(bcatcstr(dstfile, "/"));
+                    EC_ZERO(bcatcstr(dstfile, basename(argv[optind])));
+                } else {
+                    /* its an existing file, truncate */
+                    EC_ZERO_LOG(truncate(argv[argc-1], 0));
+                    EC_NULL(dstfile = bfromcstr(argv[argc-1]));
+                }
+            } else {
+                EC_NULL(dstfile = bfromcstr(argv[argc-1]));
+            }
             newvol(argv[optind], &srcvol);
-            ad_cp_copy(&srcvol, &dstvol, srcfile, path, &sst);
+            printf("Source: %s, Destination: %s\n", argv[optind], cfrombstring(dstfile));
+            ad_cp_copy(&srcvol, &dstvol, argv[optind], cfrombstring(dstfile), &sst);
             freevol(&srcvol);
             freevol(&dstvol);
             
@@ -293,8 +320,8 @@ int ad_cp(int argc, char **argv)
         } /* while */
     } /* else (numpath>2) */
 
+EC_CLEANUP:
     freevol(&dstvol);
 
-    return 0;
-
+    EC_EXIT;
 }
index 339a72b40b66dd6ecec18bd110501f27f0ded0fd..5ba6471b686a0e8ab79f70c5f1b0a8205c5a39e1 100644 (file)
@@ -1,6 +1,4 @@
 /* 
-   $Id: ad_util.c,v 1.2 2009-10-14 02:30:42 didg Exp $
-
    Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
    
    This program is free software; you can redistribute it and/or modify