]> arthur.barton.de Git - netatalk.git/blobdiff - bin/ad/ad_cp.c
Merge 2-1
[netatalk.git] / bin / ad / ad_cp.c
index e9a2d3684c84f7cf1f16d26b44ce65f701c9bd6e..ac0a737a0b5a12cfcc3477ace70f282ba7f5a3e4 100644 (file)
@@ -59,6 +59,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <libgen.h>
 
 #include <atalk/ftw.h>
 #include <atalk/adouble.h>
@@ -386,6 +387,10 @@ static int copy(const char *path,
     if (alarmed)
         return -1;
 
+    /* This currently doesn't work with "." */
+    if (strcmp(path, ".") == 0) {
+        ERROR("\".\" not supported");
+    }
     const char *dir = strrchr(path, '/');
     if (dir == NULL)
         dir = path;
@@ -526,11 +531,15 @@ static int copy(const char *path,
 
             /* Get CNID of Parent and add new childir to CNID database */
             ppdid = pdid;
-            did = cnid_for_path(&dvolume.volinfo, &dvolume.volume, to.p_path, &pdid);
+            if ((did = cnid_for_path(&dvolume, to.p_path, &pdid)) == CNID_INVALID) {
+                SLOG("Error resolving CNID for %s", to.p_path);
+                badcp = rval = 1;
+                return -1;
+            }
 
             struct adouble ad;
             struct stat st;
-            if (stat(to.p_path, &st) != 0) {
+            if (lstat(to.p_path, &st) != 0) {
                 badcp = rval = 1;
                 break;
             }
@@ -588,11 +597,16 @@ static int copy(const char *path,
 
             /* Get CNID of Parent and add new childir to CNID database */
             pdid = did;
-            cnid_t cnid = cnid_for_path(&dvolume.volinfo, &dvolume.volume, to.p_path, &did);
+            cnid_t cnid;
+            if ((cnid = cnid_for_path(&dvolume, to.p_path, &did)) == CNID_INVALID) {
+                SLOG("Error resolving CNID for %s", to.p_path);
+                badcp = rval = 1;
+                return -1;
+            }
 
             struct adouble ad;
             struct stat st;
-            if (stat(to.p_path, &st) != 0) {
+            if (lstat(to.p_path, &st) != 0) {
                 badcp = rval = 1;
                 break;
             }
@@ -829,8 +843,8 @@ static int setfile(const struct stat *fs, int fd)
 
     TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atim);
     TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtim);
-    if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) {
-        SLOG("%sutimes: %s", islink ? "l" : "", to.p_path);
+    if (utimes(to.p_path, tv)) {
+        SLOG("utimes: %s", to.p_path);
         rval = 1;
     }
     if (fdval ? fstat(fd, &ts) :