}
/* ------------------ */
-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;
}
/* ------------------ */
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;
}
#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
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) );