auto sync: support local sync configs (BMC #20970)
Due to too restrictive checking of the syncURL, configs without http or obex-bt were never executed automatically. This commit adds a fallback which enables "other" configs to run without checking for peer presence. In addition it marks all "local" syncs as needing HTTP connectivity. This is a simplification that fits the current use cases, but needs to be enhanced later on.
This commit is contained in:
parent
f47d31580d
commit
68b61edd6e
|
@ -735,22 +735,25 @@ class AutoSyncManager : public SessionListener
|
|||
string m_peer;
|
||||
/** the time that the peer must at least have been around (seconds) */
|
||||
unsigned int m_delay;
|
||||
/** the 'syncURL' used by synchronization. It always contains only one sync URL. */
|
||||
string m_url;
|
||||
/** each task matches with exactly one transport supported for a peer */
|
||||
enum Transport {
|
||||
NEEDS_HTTP,
|
||||
NEEDS_BT,
|
||||
NEEDS_OTHER
|
||||
} m_transport;
|
||||
/** individual sync URL for which this task was created, matches m_transport */
|
||||
std::string m_url;
|
||||
|
||||
AutoSyncTask(const string &peer, unsigned int delay, const string &url)
|
||||
: m_peer(peer), m_delay(delay), m_url(url)
|
||||
AutoSyncTask(const string &peer, unsigned int delay, Transport transport, const std::string &url)
|
||||
: m_peer(peer), m_delay(delay), m_transport(transport), m_url(url)
|
||||
{
|
||||
}
|
||||
|
||||
/** compare whether two tasks are the same. May refine it later with more information */
|
||||
bool operator==(const AutoSyncTask &right) const
|
||||
{
|
||||
if(boost::iequals(m_peer, right.m_peer) &&
|
||||
boost::iequals(m_url, right.m_url)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return boost::iequals(m_peer, right.m_peer) &&
|
||||
m_url == right.m_url;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -6527,9 +6530,20 @@ void AutoSyncManager::initConfig(const string &configName)
|
|||
interval, duration);
|
||||
|
||||
BOOST_FOREACH(string url, urls) {
|
||||
if((boost::istarts_with(url, "http") && http)
|
||||
|| (boost::istarts_with(url, "obex-bt") && bt)) {
|
||||
AutoSyncTask syncTask(configName, duration, url);
|
||||
AutoSyncTask::Transport transport = AutoSyncTask::NEEDS_OTHER; // fallback for unknown sync URL
|
||||
if (boost::istarts_with(url, "http")) {
|
||||
transport = AutoSyncTask::NEEDS_HTTP;
|
||||
} else if (boost::istarts_with(url, "local")) {
|
||||
// TODO: instead of assuming that local sync needs HTTP, really look into the target config
|
||||
// and determine what the peerType is
|
||||
transport = AutoSyncTask::NEEDS_HTTP;
|
||||
} else if (boost::istarts_with(url, "obex-bt")) {
|
||||
transport = AutoSyncTask::NEEDS_BT;
|
||||
}
|
||||
if((transport == AutoSyncTask::NEEDS_HTTP && http) ||
|
||||
(transport == AutoSyncTask::NEEDS_BT && bt) ||
|
||||
(transport == AutoSyncTask::NEEDS_OTHER)) {
|
||||
AutoSyncTask syncTask(configName, duration, transport, url);
|
||||
PeerMap::iterator it = m_peerMap.find(interval);
|
||||
if(it != m_peerMap.end()) {
|
||||
SE_LOG_DEBUG(NULL, NULL,
|
||||
|
@ -6657,12 +6671,8 @@ bool AutoSyncManager::findTask(const AutoSyncTask &syncTask)
|
|||
bool AutoSyncManager::taskLikelyToRun(const AutoSyncTask &syncTask)
|
||||
{
|
||||
PresenceStatus &status = m_server.getPresenceStatus();
|
||||
// avoid doing any checking of task list if http and bt presence are false
|
||||
if(!status.getHttpPresence() && !status.getBtPresence()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(boost::istarts_with(syncTask.m_url, "http") && status.getHttpPresence()) {
|
||||
if (syncTask.m_transport == AutoSyncTask::NEEDS_HTTP && status.getHttpPresence()) {
|
||||
// don't add duplicate tasks
|
||||
if(!findTask(syncTask)) {
|
||||
Timer& timer = status.getHttpTimer();
|
||||
|
@ -6672,7 +6682,8 @@ bool AutoSyncManager::taskLikelyToRun(const AutoSyncTask &syncTask)
|
|||
return true;
|
||||
}
|
||||
}
|
||||
} else if (boost::istarts_with(syncTask.m_url, "obex-bt") && status.getBtPresence()) {
|
||||
} else if ((syncTask.m_transport == AutoSyncTask::NEEDS_BT && status.getBtPresence()) ||
|
||||
syncTask.m_transport == AutoSyncTask::NEEDS_OTHER) {
|
||||
// don't add duplicate tasks
|
||||
if(!findTask(syncTask)) {
|
||||
return true;
|
||||
|
@ -6718,7 +6729,7 @@ void AutoSyncManager::prepare()
|
|||
|
||||
string mode;
|
||||
Session::SourceModes_t sourceModes;
|
||||
m_session->sync(mode, sourceModes);
|
||||
m_session->sync("", Session::SourceModes_t());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1928,6 +1928,52 @@ class TestSessionAPIsDummy(unittest.TestCase, DBusUtil):
|
|||
self.failUnless(delta < 13)
|
||||
self.failUnless(delta > 7)
|
||||
|
||||
@timeout(60)
|
||||
def testAutoSyncLocal(self):
|
||||
"""TestSessionAPIsDummy.testAutoSyncLocal - test that auto-sync is triggered for local sync"""
|
||||
self.setupConfig()
|
||||
# enable auto-sync
|
||||
config = self.config
|
||||
config[""]["syncURL"] = "local://@foobar" # will fail
|
||||
config[""]["autoSync"] = "1"
|
||||
config[""]["autoSyncDelay"] = "0"
|
||||
config[""]["autoSyncInterval"] = "10s"
|
||||
config[""]["password"] = "foobar"
|
||||
self.session.SetConfig(True, False, config, utf8_strings=True)
|
||||
|
||||
def session_ready(object, ready):
|
||||
if self.running and object != self.sessionpath:
|
||||
self.auto_sync_session_path = object
|
||||
DBusUtil.quit_events.append("session " + object + (ready and " ready" or " done"))
|
||||
loop.quit()
|
||||
|
||||
signal = bus.add_signal_receiver(session_ready,
|
||||
'SessionChanged',
|
||||
'org.syncevolution.Server',
|
||||
'org.syncevolution',
|
||||
None,
|
||||
byte_arrays=True,
|
||||
utf8_strings=True)
|
||||
|
||||
# shut down current session, will allow auto-sync
|
||||
self.session.Detach()
|
||||
|
||||
# wait for start and end of auto-sync session
|
||||
loop.run()
|
||||
loop.run()
|
||||
self.failUnlessEqual(DBusUtil.quit_events, ["session " + self.auto_sync_session_path + " ready",
|
||||
"session " + self.auto_sync_session_path + " done"])
|
||||
session = dbus.Interface(bus.get_object('org.syncevolution',
|
||||
self.auto_sync_session_path),
|
||||
'org.syncevolution.Session')
|
||||
reports = session.GetReports(0, 100, utf8_strings=True)
|
||||
self.failUnlessEqual(len(reports), 1)
|
||||
self.failUnlessEqual(reports[0]["status"], "10500")
|
||||
name = session.GetConfigName()
|
||||
self.failUnlessEqual(name, "dummy-test")
|
||||
flags = session.GetFlags()
|
||||
self.failUnlessEqual(flags, [])
|
||||
|
||||
|
||||
class TestSessionAPIsReal(unittest.TestCase, DBusUtil):
|
||||
""" This class is used to test those unit tests of session APIs, depending on doing sync.
|
||||
|
|
Loading…
Reference in New Issue