[gnote] Do synchronize if lock file has expired



commit d82a180a9f4ae696bfabe6f02c67d6f36c9a4476
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Mar 29 22:24:46 2020 +0300

    Do synchronize if lock file has expired

 src/synchronization/filesystemsyncserver.cpp | 34 ++++------------------------
 src/synchronization/filesystemsyncserver.hpp |  2 --
 2 files changed, 4 insertions(+), 32 deletions(-)
---
diff --git a/src/synchronization/filesystemsyncserver.cpp b/src/synchronization/filesystemsyncserver.cpp
index 5f64c010..fdff4eb7 100644
--- a/src/synchronization/filesystemsyncserver.cpp
+++ b/src/synchronization/filesystemsyncserver.cpp
@@ -194,41 +194,15 @@ bool FileSystemSyncServer::begin_sync_transaction()
   // client should record the time elapsed
   if(m_lock_path->query_exists()) {
     SyncLockInfo currentSyncLock = current_sync_lock();
-    if(!m_initial_sync_attempt) {
+    auto file_info = m_lock_path->query_info();
+    auto lock_expires = file_info->get_modification_date_time().to_utc().add(currentSyncLock.duration);
+    auto now = Glib::DateTime::create_now_utc();
+    if(now < lock_expires) {
       DBG_OUT("Sync: Discovered a sync lock file, wait at least %s before trying again.", 
sharp::time_span_string(currentSyncLock.duration).c_str());
-      // This is our initial attempt to sync and we've detected
-      // a sync file, so we're gonna have to wait.
-      m_initial_sync_attempt = Glib::DateTime::create_now_utc();
-      m_last_sync_lock_hash = currentSyncLock.hash_string();
       return false;
     }
-    else if(m_last_sync_lock_hash != currentSyncLock.hash_string()) {
-      DBG_OUT("Sync: Updated sync lock file discovered, wait at least %s before trying again.", 
sharp::time_span_string(currentSyncLock.duration).c_str());
-      // The sync lock has been updated and is still a valid lock
-      m_initial_sync_attempt = Glib::DateTime::create_now_utc();
-      m_last_sync_lock_hash = currentSyncLock.hash_string();
-      return false;
-    }
-    else {
-      if(m_last_sync_lock_hash == currentSyncLock.hash_string()) {
-        // The sync lock has is the same so check to see if the
-        // duration of the lock has expired.  If it hasn't, wait
-        // even longer.
-        if(Glib::DateTime::create_now_utc().add(-currentSyncLock.duration) < m_initial_sync_attempt) {
-          DBG_OUT("Sync: You haven't waited long enough for the sync file to expire.");
-          return false;
-        }
-      }
-
-      // Cleanup Old Sync Lock!
-      cleanup_old_sync(currentSyncLock);
-    }
   }
 
-  // Reset the initialSyncAttempt
-  m_initial_sync_attempt = Glib::DateTime();
-  m_last_sync_lock_hash = "";
-
   // Create a new lock file so other clients know another client is
   // actively synchronizing right now.
   m_sync_lock.renew_count = 0;
diff --git a/src/synchronization/filesystemsyncserver.hpp b/src/synchronization/filesystemsyncserver.hpp
index d5b32b7a..cf86adf6 100644
--- a/src/synchronization/filesystemsyncserver.hpp
+++ b/src/synchronization/filesystemsyncserver.hpp
@@ -69,8 +69,6 @@ private:
   int m_new_revision;
   Glib::RefPtr<Gio::File> m_new_revision_path;
 
-  Glib::DateTime m_initial_sync_attempt;
-  Glib::ustring m_last_sync_lock_hash;
   utils::InterruptableTimeout m_lock_timeout;
   SyncLockInfo m_sync_lock;
 };


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]