From 0aea8db7e1a59e8cf88436f78019685c9aff6332 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 13 Jun 2016 12:32:33 +0600 Subject: CLOUD: Make Storage::savesSync() restart If Storage::syncSaves() is called when sync is running, another sync would be automatically scheduled in the end of the current one. That could be helpful when we want to specify that we changed something during sync (created new save slot, for example). --- backends/cloud/storage.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'backends/cloud/storage.cpp') diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp index 08ab9e9c90..b98f213327 100644 --- a/backends/cloud/storage.cpp +++ b/backends/cloud/storage.cpp @@ -52,12 +52,18 @@ Networking::Request *Storage::addRequest(Networking::Request *request) { } void Storage::requestFinishedCallback(Networking::Request *invalidRequestPointer) { + bool restartSync = false; + _runningRequestsMutex.lock(); if (invalidRequestPointer == _savesSyncRequest) _savesSyncRequest = nullptr; --_runningRequestsCount; - if (_runningRequestsCount == 0) debug("Storage is not working now"); + if (_syncRestartRequestsed) restartSync = true; + if (_runningRequestsCount == 0 && !restartSync) debug("Storage is not working now"); _runningRequestsMutex.unlock(); + + if (restartSync) + syncSaves(nullptr, nullptr); } Networking::Request *Storage::upload(Common::String remotePath, Common::String localPath, UploadCallback callback, Networking::ErrorCallback errorCallback) { @@ -111,11 +117,13 @@ SavesSyncRequest *Storage::syncSaves(BoolCallback callback, Networking::ErrorCal _runningRequestsMutex.lock(); if (_savesSyncRequest) { warning("Storage::syncSaves: there is a sync in progress already"); + _syncRestartRequestsed = true; _runningRequestsMutex.unlock(); return _savesSyncRequest; } if (!errorCallback) errorCallback = getErrorPrintingCallback(); _savesSyncRequest = new SavesSyncRequest(this, callback, errorCallback); + _syncRestartRequestsed = false; _runningRequestsMutex.unlock(); return (SavesSyncRequest *)addRequest(_savesSyncRequest); //who knows what that ConnMan could return in the future } -- cgit v1.2.3