]> arthur.barton.de Git - netatalk.git/commitdiff
Trying to get rel_path right
authorFrank Lahm <franklahm@googlemail.com>
Thu, 14 Oct 2010 15:15:18 +0000 (17:15 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Thu, 14 Oct 2010 15:15:18 +0000 (17:15 +0200)
bin/ad/ad_mv.c
bin/ad/ad_util.c

index b7c611d95243f573ab70dc04b2631c1d2ae70596..0c973d06a7ac64c603841f5705a2d32e951d01fe 100644 (file)
@@ -207,6 +207,7 @@ int ad_mv(int argc, char *argv[])
         rval = do_move(argv[0], argv[1]);
         closevol(&svolume);
         closevol(&dvolume);
+        return 1;
     }
 
     /* It's a directory, move each file into it. */
index 24bee8ad8761530d5f87a75f04c90c3ee296b885..972c2484b2e0fd0fda60b95016ce9683df12b279 100644 (file)
@@ -202,14 +202,38 @@ static bstring rel_path_in_vol(const char *path, const char *volpath)
     int cwd = -1;
     bstring fpath = NULL;
     char *dname = NULL;
+    struct stat st;
 
     if (path == NULL || volpath == NULL)
         return NULL;
 
     EC_NEG1_LOG(cwd = open(".", O_RDONLY));
-    EC_NULL_LOG(dname = strdup(path));
-    EC_ZERO_LOGSTR(chdir(dirname(dname)), "chdir(%s): %s", dirname, strerror(errno));
-    EC_NULL(fpath = bfromcstr(getcwdpath()));
+
+    EC_ZERO_LOGSTR(stat(path, &st), "stat(%s): %s", path, strerror(errno));
+    switch (S_IFMT & st.st_mode) {
+
+    case S_IFREG:
+        EC_NULL_LOG(dname = strdup(path));
+        EC_ZERO_LOGSTR(chdir(dirname(dname)), "chdir(%s): %s", dirname, strerror(errno));
+        free(dname);
+        dname = NULL;
+        EC_NULL(fpath = bfromcstr(getcwdpath()));
+        BSTRING_STRIP_SLASH(fpath);
+        EC_ZERO(bcatcstr(fpath, "/"));
+        EC_NULL_LOG(dname = strdup(path));
+        EC_ZERO(bcatcstr(fpath, basename(dname)));
+        break;
+
+    case S_IFDIR:
+        EC_ZERO_LOGSTR(chdir(path), "chdir(%s): %s", path, strerror(errno));
+        EC_NULL(fpath = bfromcstr(getcwdpath()));
+        break;
+
+    default:
+        SLOG("special: %s", path);
+        EC_FAIL;
+    }
+
     BSTRING_STRIP_SLASH(fpath);
 
     /*