From 2ec0b63f985a3b4eafef4fa0c36b99a75e92f3a5 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Thu, 4 Oct 2012 13:02:38 +0200 Subject: [PATCH] Migrate existing database from $HOME/.csync if non exists at config dir. --- src/csync_statedb.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/csync_statedb.c b/src/csync_statedb.c index e51e1abab0..e1c214fd38 100644 --- a/src/csync_statedb.c +++ b/src/csync_statedb.c @@ -35,6 +35,7 @@ #include "csync_private.h" #include "csync_statedb.h" #include "csync_util.h" +#include "csync_misc.h" #define CSYNC_LOG_CATEGORY_NAME "csync.statedb" #include "csync_log.h" @@ -108,6 +109,47 @@ int csync_statedb_load(CSYNC *ctx, const char *statedb) { c_strlist_t *result = NULL; char *statedb_tmp = NULL; + /* check if the statedb is existing. If not, check if there is still one + * left over in $HOME/.csync and copy it over (migration path) + */ + if( !c_isfile(statedb) ) { + char *home = NULL; + char *home_statedb = NULL; + char *statedb_file = NULL; + + /* there is no statedb at the expected place. */ + + home = csync_get_user_home_dir(); + statedb_file = c_basename(statedb); + + rc = asprintf(&home_statedb, "%s/%s/%s", home, CSYNC_CONF_DIR, statedb_file); + SAFE_FREE(home); + SAFE_FREE(statedb_file); + + if (rc < 0) { + goto out; + } + + CSYNC_LOG(CSYNC_LOG_PRIORITY_NOTICE, "statedb %s not found, checking %s", + statedb, home_statedb); + + /* check the home file and copy to new statedb if existing. */ + if(c_isfile(home_statedb)) { + if (c_copy(home_statedb, statedb, 0644) < 0) { + /* copy failed, but that is not reason to die. */ + CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "Could not copy file %s => %s", + home_statedb, statedb ); + } else { + CSYNC_LOG(CSYNC_LOG_PRIORITY_NOTICE, "Copied %s => %s", + home_statedb, statedb ); + } + } + SAFE_FREE(home_statedb); + } + + /* csync_statedb_check tries to open the statedb and creates it in case + * its not there. + */ if (_csync_statedb_check(statedb) < 0) { rc = -1; goto out;