From 72ec12b0e0798bb7e22dd5526fdccfad8fcb0fc0 Mon Sep 17 00:00:00 2001 From: Frank Lahm Date: Thu, 15 Mar 2012 06:57:51 +0100 Subject: [PATCH] Move AppleDB --- config/Makefile.am | 2 ++ etc/cnid_dbd/cnid_metad.c | 38 ++++++++++++++++++++++++----------- libatalk/util/netatalk_conf.c | 9 +++++++-- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/config/Makefile.am b/config/Makefile.am index 272087aa..39f79739 100644 --- a/config/Makefile.am +++ b/config/Makefile.am @@ -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 \ diff --git a/etc/cnid_dbd/cnid_metad.c b/etc/cnid_dbd/cnid_metad.c index 7b86219c..a264bd88 100644 --- a/etc/cnid_dbd/cnid_metad.c +++ b/etc/cnid_dbd/cnid_metad.c @@ -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; } diff --git a/libatalk/util/netatalk_conf.c b/libatalk/util/netatalk_conf.c index cf98a00c..3425c741 100644 --- a/libatalk/util/netatalk_conf.c +++ b/libatalk/util/netatalk_conf.c @@ -44,6 +44,7 @@ #include #include #include +#include #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) ); -- 2.39.2