]> arthur.barton.de Git - netatalk.git/commitdiff
Move AppleDB
authorFrank Lahm <franklahm@googlemail.com>
Thu, 15 Mar 2012 05:57:51 +0000 (06:57 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Thu, 15 Mar 2012 05:57:51 +0000 (06:57 +0100)
config/Makefile.am
etc/cnid_dbd/cnid_metad.c
libatalk/util/netatalk_conf.c

index 272087aa502cccfc54b69024a3640fd14a416243..39f797395f4ad9ff4abef67b4a2be4ae9870dc43 100644 (file)
@@ -30,7 +30,9 @@ pkgconfdir = @PKGCONFDIR@
 
 install-data-local: install-config-files
        mkdir -pm 0755 $(DESTDIR)$(localstatedir)/netatalk/
+       mkdir -pm 0755 $(DESTDIR)$(localstatedir)/netatalk/CNID/
        $(INSTALL_DATA) README $(DESTDIR)$(localstatedir)/netatalk/
+       $(INSTALL_DATA) README $(DESTDIR)$(localstatedir)/netatalk/CNID/
 
 uninstall-local:
        for f in $(CONFFILES) $(GENFILES); do \
index 7b86219cf73e349e6edc2bb05a254786a8d50ad3..a264bd8874eb2127193f620b8df1813a3e216f66 100644 (file)
@@ -277,28 +277,42 @@ static int maybe_start_dbd(const AFPObj *obj, char *dbdpn, const char *volpath)
 }
 
 /* ------------------ */
-static int set_dbdir(char *dbdir)
+static int set_dbdir(const char *dbdir, const char *vpath)
 {
-    int len;
+    EC_INIT;
+    int status;
     struct stat st;
+    bstring oldpath, newpath, cmd = NULL;
 
-    len = strlen(dbdir);
+    EC_NULL_LOG( oldpath = bformat("%s/%s/", vpath, DBHOME) );
+    EC_NULL_LOG( newpath = bformat("%s/%s/", dbdir, DBHOME) );
 
-    if (stat(dbdir, &st) < 0 && mkdir(dbdir, 0755) < 0) {
+    if (lstat(dbdir, &st) < 0 && mkdir(dbdir, 0755) < 0) {
         LOG(log_error, logtype_cnid, "set_dbdir: mkdir failed for %s", dbdir);
         return -1;
     }
 
-    if (dbdir[len - 1] != '/') {
-        strcat(dbdir, "/");
-        len++;
+    if (lstat(bdata(oldpath), &st) == 0 && lstat(bdata(newpath), &st) != 0 && errno == ENOENT) {
+        /* There's an .AppleDB in the volume root, we move it */
+        EC_NULL_LOG( cmd = bformat("mv '%s' '%s'", bdata(oldpath), dbdir) );
+        LOG(log_debug, logtype_cnid, "set_dbdir: cmd: %s", bdata(cmd));
+        if (WEXITSTATUS(system(bdata(cmd))) != 0) {
+            LOG(log_error, logtype_cnid, "set_dbdir: moving CNID db from \"%s\" to \"%s\" failed",
+                bdata(oldpath), dbdir);
+            EC_FAIL;
+        }
     }
-    strcpy(dbdir + len, DBHOME);
-    if (stat(dbdir, &st) < 0 && mkdir(dbdir, 0755 ) < 0) {
-        LOG(log_error, logtype_cnid, "set_dbdir: mkdir failed for %s", dbdir);
+
+    if (lstat(bdata(newpath), &st) < 0 && mkdir(bdata(newpath), 0755 ) < 0) {
+        LOG(log_error, logtype_cnid, "set_dbdir: mkdir failed for %s", bdata(newpath));
         return -1;
     }
-    return 0;
+
+EC_CLEANUP:
+    bdestroy(oldpath);
+    bdestroy(newpath);
+    bdestroy(cmd);
+    EC_EXIT;
 }
 
 /* ------------------ */
@@ -594,7 +608,7 @@ int main(int argc, char *argv[])
 
         LOG(log_maxdebug, logtype_cnid, "main: dbpath: %s", vol->v_dbpath);
 
-        if (set_dbdir(vol->v_dbpath) < 0) {
+        if (set_dbdir(vol->v_dbpath, volpath) < 0) {
             goto loop_end;
         }
 
index cf98a00c3da2fcdb1669d0b84da27b9850a07af7..3425c741bf4b46cec209f80674de187ad163821f 100644 (file)
@@ -44,6 +44,7 @@
 #include <atalk/dsi.h>
 #include <atalk/uuid.h>
 #include <atalk/netatalk_conf.h>
+#include <atalk/bstrlib.h>
 
 #define VOLPASSLEN  8
 #ifndef UUID_PRINTABLE_STRING_LENGTH
@@ -608,8 +609,12 @@ static struct vol *creatvol(AFPObj *obj,
     else
         EC_NULL( volume->v_maccodepage = strdup(obj->options.maccodepage) );
 
-    val = getoption(obj->iniconfig, section, "dbpath", preset);
-    EC_NULL( volume->v_dbpath = volxlate(obj, NULL, MAXPATHLEN, val ? val : path, pwd, path, name) );
+    bstring dbpath;
+    if ((val = getoption(obj->iniconfig, section, "dbpath", preset)) == NULL)
+        val = _PATH_STATEDIR "CNID/";
+    EC_NULL_LOG( dbpath = bformat("%s/%s/", val, name) );
+    volume->v_dbpath = strdup(bdata(dbpath));
+    bdestroy(dbpath);
 
     if (val = getoption(obj->iniconfig, section, "cnidscheme", preset))
         EC_NULL( volume->v_cnidscheme = strdup(val) );