From a7be3a40c9dce14f2a9072df2591e455c27b18d5 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 2 Jul 2012 19:25:33 +0200 Subject: [PATCH] Ignore remote object updates when local object is newer. --- base/configobject.cpp | 16 ++++++++++++++++ base/configobject.h | 4 ++++ components/cibsync/cibsynccomponent.cpp | 5 ++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/base/configobject.cpp b/base/configobject.cpp index 57a062f96..245da3710 100644 --- a/base/configobject.cpp +++ b/base/configobject.cpp @@ -99,12 +99,28 @@ string ConfigObject::GetSource(void) const return value; } +void ConfigObject::SetCommitTimestamp(time_t ts) +{ + GetProperties()->SetProperty("__tx", ts); +} + +time_t ConfigObject::GetCommitTimestamp(void) const +{ + long value = false; + GetProperties()->GetProperty("__tx", &value); + return value; +} + void ConfigObject::Commit(void) { ConfigObject::Ptr dobj = GetObject(GetType(), GetName()); ConfigObject::Ptr self = GetSelf(); assert(!dobj || dobj == self); m_Container->CheckObject(self); + + time_t now; + time(&now); + SetCommitTimestamp(now); } void ConfigObject::Unregister(void) diff --git a/base/configobject.h b/base/configobject.h index 84b7b6db4..82cb13136 100644 --- a/base/configobject.h +++ b/base/configobject.h @@ -82,6 +82,8 @@ public: void SetSource(const string& value); string GetSource(void) const; + time_t GetCommitTimestamp(void) const; + void Commit(void); void Unregister(void); @@ -101,6 +103,8 @@ private: Dictionary::Ptr m_Properties; Dictionary::Ptr m_Tags; + void SetCommitTimestamp(time_t ts); + static bool TypeAndNameGetter(const ConfigObject::Ptr& object, pair *key); static bool TypePredicate(const ConfigObject::Ptr& object, string type); diff --git a/components/cibsync/cibsynccomponent.cpp b/components/cibsync/cibsynccomponent.cpp index 99a23bc79..893aa92a0 100644 --- a/components/cibsync/cibsynccomponent.cpp +++ b/components/cibsync/cibsynccomponent.cpp @@ -240,7 +240,10 @@ void CIBSyncComponent::RemoteObjectCommittedHandler(const Endpoint::Ptr& sender, return; } } else { - /* TODO: compare transaction timestamps and reject the update if our local object is newer */ + ConfigObject::Ptr remoteObject = boost::make_shared(properties.GetDictionary()); + + if (object->GetCommitTimestamp() >= remoteObject->GetCommitTimestamp()) + return; object->SetProperties(properties.GetDictionary()); }