diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2009-11-25 16:10:44 +0100 |
---|---|---|
committer | Patrick Ohly <patrick.ohly@intel.com> | 2009-12-01 17:27:59 +0100 |
commit | 5ccbf8e2a29fb3b0b27a2e695f5dd7c1a7cbb19e (patch) | |
tree | d70a8344d6b32a7b904f9766b29c81e4835236c5 | |
parent | 656cc60dc55a8ba47bbbaf66af993283f94c3c38 (diff) |
syncevolution --migrate: support migration into a certain contextmigrate
This depends on peer/context awareness in the code which looks for
the old config and renames it. If the old config is not in the same
context as the new one, it is searched by peer name alone. This
works for all old-style configs as well as rewriting a peer inside
the same context.
-rw-r--r-- | src/syncevo/Cmdline.cpp | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/src/syncevo/Cmdline.cpp b/src/syncevo/Cmdline.cpp index 58c1ad77..b44ac7dd 100644 --- a/src/syncevo/Cmdline.cpp +++ b/src/syncevo/Cmdline.cpp @@ -295,10 +295,16 @@ bool Cmdline::run() { // the old config. boost::shared_ptr<SyncConfig> from; if (m_migrate) { + string oldContext = context; from.reset(new SyncConfig(m_server)); if (!from->exists()) { - m_err << "ERROR: server '" << m_server << "' has not been configured yet." << endl; - return false; + // for migration into a different context, search for config without context + oldContext = ""; + from.reset(new SyncConfig(peer)); + if (!from->exists()) { + m_err << "ERROR: server '" << m_server << "' has not been configured yet." << endl; + return false; + } } int counter = 0; @@ -324,7 +330,9 @@ bool Cmdline::run() { counter++; } - from.reset(new SyncConfig(m_server + suffix)); + from.reset(new SyncConfig(peer + suffix + + (oldContext.empty() ? "" : "@") + + oldContext)); } else { from.reset(new SyncConfig(m_server)); if (!from->exists()) { @@ -2040,6 +2048,47 @@ protected: string renamedConfig = scanFiles(oldRoot + ".old.1"); CPPUNIT_ASSERT_EQUAL_DIFF(createdConfig, renamedConfig); } + + { + string otherRoot = m_testDir + "/syncevolution/other"; + rm_r(otherRoot); + + // migrate old config into non-default context + createFiles(oldRoot, oldConfig); + string createdConfig = scanFiles(oldRoot); + { + TestCmdline cmdline("--migrate", + "scheduleworld@other", + NULL); + cmdline.doit(); + CPPUNIT_ASSERT_EQUAL_DIFF("", cmdline.m_err.str()); + CPPUNIT_ASSERT_EQUAL_DIFF("", cmdline.m_out.str()); + } + + string migratedConfig = scanFiles(otherRoot); + string expected = ScheduleWorldConfig(); + sortConfig(expected); + CPPUNIT_ASSERT_EQUAL_DIFF(expected, migratedConfig); + string renamedConfig = scanFiles(oldRoot + ".old"); + CPPUNIT_ASSERT_EQUAL_DIFF(createdConfig, renamedConfig); + + // migrate the migrated config again inside the "other" context + { + TestCmdline cmdline("--migrate", + "scheduleworld@other", + NULL); + cmdline.doit(); + CPPUNIT_ASSERT_EQUAL_DIFF("", cmdline.m_err.str()); + CPPUNIT_ASSERT_EQUAL_DIFF("", cmdline.m_out.str()); + } + migratedConfig = scanFiles(otherRoot, "scheduleworld"); + expected = ScheduleWorldConfig(); + sortConfig(expected); + CPPUNIT_ASSERT_EQUAL_DIFF(expected, migratedConfig); + renamedConfig = scanFiles(otherRoot, "scheduleworld.old"); + boost::replace_all(expected, "/scheduleworld/", "/scheduleworld.old/"); + CPPUNIT_ASSERT_EQUAL_DIFF(expected, renamedConfig); + } } const string m_testDir; |