]> arthur.barton.de Git - netatalk.git/commitdiff
Move function cnid_for_path to CNID utility libatalk file
authorFrank Lahm <franklahm@googlemail.com>
Thu, 20 Sep 2012 12:13:31 +0000 (14:13 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Thu, 20 Sep 2012 12:13:31 +0000 (14:13 +0200)
bin/ad/ad.h
bin/ad/ad_cp.c
bin/ad/ad_mv.c
bin/ad/ad_rm.c
bin/ad/ad_util.c
include/atalk/util.h
libatalk/util/cnid.c

index 3195641f7cb291c78e66d580a4d3a047f9d53997..9155900c990f3f9f02773a11ffc7b6f1ea3fcbb6 100644 (file)
@@ -69,7 +69,6 @@ extern int ad_find(int argc, char **argv, AFPObj *obj);
 /* ad_util.c */
 extern int openvol(AFPObj *obj, const char *path, afpvol_t *vol);
 extern void closevol(afpvol_t *vol);
-extern cnid_t cnid_for_path(const afpvol_t *vol, const char *path, cnid_t *did);
 extern cnid_t cnid_for_paths_parent(const afpvol_t *vol, const char *path, cnid_t *did);
 extern char *utompath(const struct vol *, const char *);
 extern int convert_dots_encoding(const afpvol_t *svol, const afpvol_t *dvol, char *path, size_t buflen);
index ef995ce8cf3f159c6346a5e32a4858e9cfad8948..61b94b5e0f275d849211b076b85a9c5fb95cbfe0 100644 (file)
@@ -531,7 +531,7 @@ static int copy(const char *path,
 
             /* Get CNID of Parent and add new childir to CNID database */
             ppdid = pdid;
-            if ((did = cnid_for_path(&dvolume, to.p_path, &pdid)) == CNID_INVALID) {
+            if ((did = cnid_for_path(dvolume.vol->v_cdb, dvolume.vol->v_path, to.p_path, &pdid)) == CNID_INVALID) {
                 SLOG("Error resolving CNID for %s", to.p_path);
                 badcp = rval = 1;
                 return -1;
@@ -599,7 +599,7 @@ static int copy(const char *path,
             /* Get CNID of Parent and add new childir to CNID database */
             pdid = did;
             cnid_t cnid;
-            if ((cnid = cnid_for_path(&dvolume, to.p_path, &did)) == CNID_INVALID) {
+            if ((cnid = cnid_for_path(dvolume.vol->v_cdb, dvolume.vol->v_path, to.p_path, &did)) == CNID_INVALID) {
                 SLOG("Error resolving CNID for %s", to.p_path);
                 badcp = rval = 1;
                 return -1;
index 7f592dd27e1aaf0623bb2a2e34038e13a6468b33..e48cae99976614237413bc5cf3208ad3ee9e5db0 100644 (file)
@@ -301,7 +301,7 @@ static int do_move(const char *from, const char *to)
     
     cnid_t cnid = 0;
     if (!mustcopy) {
-        if ((cnid = cnid_for_path(&svolume, from, &did)) == CNID_INVALID) {
+        if ((cnid = cnid_for_path(svolume.vol->v_cdb, svolume.vol->v_path, from, &did)) == CNID_INVALID) {
             SLOG("Couldn't resolve CNID for %s", from);
             return -1;
         }
index 195fee06979301eeef8e9e80d1c66c7d34f00904..b32e659fad5ff73a833a0c6de20575adcde66fb5 100644 (file)
@@ -211,7 +211,7 @@ static int rm(const char *path,
 
             /* Get CNID of Parent and add new childir to CNID database */
             pdid = did;
-            if ((cnid = cnid_for_path(&volume, path, &did)) == CNID_INVALID) {
+            if ((cnid = cnid_for_path(volume.vol->v_cdb, volume.vol->v_path, path, &did)) == CNID_INVALID) {
                 SLOG("Error resolving CNID for %s", path);
                 return -1;
             }
@@ -247,7 +247,7 @@ static int rm(const char *path,
             }
 
             /* Get CNID of Parent and add new childir to CNID database */
-            if ((did = cnid_for_path(&volume, path, &pdid)) == CNID_INVALID) {
+            if ((did = cnid_for_path(volume.vol->v_cdb, volume.vol->v_path, path, &pdid)) == CNID_INVALID) {
                 SLOG("Error resolving CNID for %s", path);
                 return -1;
             }
@@ -293,7 +293,7 @@ static int rm(const char *path,
 
             /* Get CNID of Parent and add new childir to CNID database */
             pdid = did;
-            if ((cnid = cnid_for_path(&volume, path, &did)) == CNID_INVALID) {
+            if ((cnid = cnid_for_path(volume.vol->v_cdb, volume.vol->v_path, path, &did)) == CNID_INVALID) {
                 SLOG("Error resolving CNID for %s", path);
                 return -1;
             }
index 897bdf3b1415c609efdae24f2104d019ef3464fc..135bf7abdc83b1be94e8b419f3de6e0cf46fa00c 100644 (file)
@@ -231,73 +231,6 @@ int convert_dots_encoding(const afpvol_t *svol, const afpvol_t *dvol, char *path
     return 0;
 }
 
-/*!
- * ResolvesCNID of a given paths
- *
- * path might be:
- * (a) relative:
- *     "dir/subdir" with cwd: "/afp_volume/topdir"
- * (b) absolute:
- *     "/afp_volume/dir/subdir"
- *
- * path MUST be pointing inside vol, this is usually the case as vol has been build from
- * path using loadvolinfo and friends.
- *
- * @param vol  (r) pointer to afpvol_t
- * @param path (r) path, see above
- * @param did  (rw) parent CNID of returned CNID
- *
- * @returns CNID of path
- */
-cnid_t cnid_for_path(const afpvol_t *vol,
-                     const char *path,
-                     cnid_t *did)
-{
-    EC_INIT;
-
-    cnid_t cnid;
-    bstring rpath = NULL;
-    bstring statpath = NULL;
-    struct bstrList *l = NULL;
-    struct stat st;
-
-    cnid = htonl(2);
-
-    EC_NULL(rpath = rel_path_in_vol(path, vol->vol->v_path));
-    EC_NULL(statpath = bfromcstr(vol->vol->v_path));
-    EC_ZERO(bcatcstr(statpath, "/"));
-
-    l = bsplit(rpath, '/');
-    for (int i = 0; i < l->qty ; i++) {
-        *did = cnid;
-
-        EC_ZERO(bconcat(statpath, l->entry[i]));
-        EC_ZERO_LOGSTR(lstat(cfrombstr(statpath), &st),
-                       "lstat(rpath: %s, elem: %s): %s: %s",
-                       cfrombstr(rpath), cfrombstr(l->entry[i]),
-                       cfrombstr(statpath), strerror(errno));
-
-        if ((cnid = cnid_add(vol->vol->v_cdb,
-                             &st,
-                             *did,
-                             cfrombstr(l->entry[i]),
-                             blength(l->entry[i]),
-                             0)) == CNID_INVALID) {
-            EC_FAIL;
-        }
-        EC_ZERO(bcatcstr(statpath, "/"));
-    }
-
-EC_CLEANUP:
-    bdestroy(rpath);
-    bstrListDestroy(l);
-    bdestroy(statpath);
-    if (ret != 0)
-        return CNID_INVALID;
-
-    return cnid;
-}
-
 /*!
  * Resolves CNID of a given paths parent directory
  *
index c5b23ee6f9eaeca3687c0a884d6b5a0c5c614c63..e5025bef0f60fd1cb0ae667722ece5c1b5b34c7d 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <atalk/unicode.h>
 #include <atalk/bstrlib.h>
+#include <atalk/cnid.h>
 
 /* exit error codes */
 #define EXITERR_CLNT 1  /* client related error */
@@ -188,5 +189,6 @@ extern int run_cmd(const char *cmd, char **cmd_argv);
  *****************************************************************/
 
 extern bstring rel_path_in_vol(const char *path, const char *volpath);
+extern cnid_t cnid_for_path(struct _cnid_db *cdb, const char *volpath, const char *path, cnid_t *did);
 
 #endif  /* _ATALK_UTIL_H */
index 0cc56d49514ea4ae5ba454a009c4bdf3e5620948..54dfb55cef4ad906038b48ae764efa61b723f75a 100644 (file)
@@ -35,7 +35,7 @@
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/stat.h>
-
+#include <arpa/inet.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
@@ -134,3 +134,72 @@ EC_CLEANUP:
         return NULL;
     return fpath;
 }
+
+/*!
+ * Resolves CNID of a given path
+ *
+ * path might be:
+ * (a) relative:
+ *     "dir/subdir" with cwd: "/afp_volume/topdir"
+ * (b) absolute:
+ *     "/afp_volume/dir/subdir"
+ *
+ * path MUST be pointing inside vol, this is usually the case as vol has been build from
+ * path using loadvolinfo and friends.
+ *
+ * @param cdb     (r) CNID db handle
+ * @param volpath (r) UNIX path of volume
+ * @param path    (r) path, see above
+ * @param did     (w) parent CNID of returned CNID
+ *
+ * @returns CNID of path
+ */
+cnid_t cnid_for_path(struct _cnid_db *cdb,
+                     const char *volpath,
+                     const char *path,
+                     cnid_t *did)
+{
+    EC_INIT;
+
+    cnid_t cnid;
+    bstring rpath = NULL;
+    bstring statpath = NULL;
+    struct bstrList *l = NULL;
+    struct stat st;
+
+    cnid = htonl(2);
+
+    EC_NULL(rpath = rel_path_in_vol(path, volpath));
+    EC_NULL(statpath = bfromcstr(volpath));
+    EC_ZERO(bcatcstr(statpath, "/"));
+
+    l = bsplit(rpath, '/');
+    for (int i = 0; i < l->qty ; i++) {
+        *did = cnid;
+
+        EC_ZERO(bconcat(statpath, l->entry[i]));
+        EC_ZERO_LOGSTR(lstat(cfrombstr(statpath), &st),
+                       "lstat(rpath: %s, elem: %s): %s: %s",
+                       cfrombstr(rpath), cfrombstr(l->entry[i]),
+                       cfrombstr(statpath), strerror(errno));
+
+        if ((cnid = cnid_add(cdb,
+                             &st,
+                             *did,
+                             cfrombstr(l->entry[i]),
+                             blength(l->entry[i]),
+                             0)) == CNID_INVALID) {
+            EC_FAIL;
+        }
+        EC_ZERO(bcatcstr(statpath, "/"));
+    }
+
+EC_CLEANUP:
+    bdestroy(rpath);
+    bstrListDestroy(l);
+    bdestroy(statpath);
+    if (ret != 0)
+        return CNID_INVALID;
+
+    return cnid;
+}