loleaflet/src/map/handler/Map.Keyboard.js | 3 + loolwsd/DocumentBroker.cpp | 49 +++++++++++++++++++++++++----- loolwsd/DocumentBroker.hpp | 4 +- loolwsd/MasterProcessSession.cpp | 19 ++++++++--- 4 files changed, 61 insertions(+), 14 deletions(-)
New commits: commit 23fc677d315f10ded866abcdc64e7b15ce1cab05 Author: Pranav Kant <[email protected]> Date: Thu Jul 14 15:19:21 2016 +0530 loolwsd: Don't upload to storage if document is unmodified If core says that document save operation failed because document was in unmodified state, don't upload to storage (hence no revision) Change-Id: I47fbc8a7bc632bb7977d263d697d665161f3b076 (cherry picked from commit da6af8b4ecba56e1bd408eb5a3302e1d35415d6b) diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp index cf7d479..2d9cecf 100644 --- a/loolwsd/DocumentBroker.cpp +++ b/loolwsd/DocumentBroker.cpp @@ -171,13 +171,22 @@ bool DocumentBroker::load(const std::string& jailId) return false; } -bool DocumentBroker::save() +bool DocumentBroker::save(bool success, const std::string& result) { std::unique_lock<std::mutex> lock(_saveMutex); const auto uri = _uriPublic.toString(); - // If we aren't potentially destroying just yet, and the file + // If save requested, but core didn't save because document was unmodified + // notify the waiting thread, if any. + if (!success && result == "unmodified") + { + Log::debug() << "Save skipped as document was not modified"; + _saveCV.notify_all(); + return true; + } + + // If we aren't destroying the last editable session just yet, and the file // timestamp hasn't changed, skip saving. const auto newFileModifiedTime = Poco::File(_storage->getLocalRootPath()).getLastModified(); if (!isMarkedToDestroy() && newFileModifiedTime == _lastFileModifiedTime) @@ -229,7 +238,7 @@ bool DocumentBroker::autoSave(const bool force, const size_t waitTimeoutMs) if (force) { Log::trace("Sending forced save command for [" + _docKey + "]."); - sent = sendUnoSave(); + sent = sendUnoSave(true); } else if (_isModified) { @@ -249,7 +258,7 @@ bool DocumentBroker::autoSave(const bool force, const size_t waitTimeoutMs) timeSinceLastSaveMs >= AutoSaveDurationMs) { Log::trace("Sending timed save command for [" + _docKey + "]."); - sent = sendUnoSave(); + sent = sendUnoSave(true); } } @@ -258,7 +267,7 @@ bool DocumentBroker::autoSave(const bool force, const size_t waitTimeoutMs) Log::trace("Waiting for save event for [" + _docKey + "]."); if (_saveCV.wait_for(lock, std::chrono::milliseconds(waitTimeoutMs)) == std::cv_status::no_timeout) { - Log::debug("Successfully persisted document [" + _docKey + "]."); + Log::debug("Successfully persisted document [" + _docKey + "] or document was not modified"); return true; } @@ -268,7 +277,7 @@ bool DocumentBroker::autoSave(const bool force, const size_t waitTimeoutMs) return sent; } -bool DocumentBroker::sendUnoSave() +bool DocumentBroker::sendUnoSave(const bool dontSaveIfUnmodified) { Log::info("Autosave triggered for doc [" + _docKey + "]."); Util::assertIsLocked(_mutex); @@ -284,8 +293,34 @@ bool DocumentBroker::sendUnoSave() // Invalidate the timestamp to force persisting. _lastFileModifiedTime.fromEpochTime(0); + std::ostringstream oss; + // arguments init + oss << "{"; + // We do not want save to terminate editing mode if we are in edit mode now - queue->put("uno .uno:Save {\"DontTerminateEdit\":{\"type\":\"boolean\",\"value\":true}}"); + // Mention DontTerminateEdit always + oss << "\"DontTerminateEdit\":" + << "{" + << "\"type\":\"boolean\"," + << "\"value\":true" + << "}"; + + // Mention DontSaveIfUnmodified + if (dontSaveIfUnmodified) + { + oss << "," + << "\"DontSaveIfUnmodified\":" + << "{" + << "\"type\":\"boolean\"," + << "\"value\":true" + << "}"; + } + + // arguments end + oss << "}"; + + Log::debug(".uno:Save arguments: " + oss.str()); + queue->put("uno .uno:Save " + oss.str()); return true; } } diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp index ca22419..53f6ec7 100644 --- a/loolwsd/DocumentBroker.hpp +++ b/loolwsd/DocumentBroker.hpp @@ -151,7 +151,7 @@ public: void setLoaded() { _isLoaded = true; } /// Save the document to Storage if needs persisting. - bool save(); + bool save(bool success, const std::string& result = ""); bool isModified() const { return _isModified; } void setModified(const bool value); @@ -212,7 +212,7 @@ public: private: /// Sends the .uno:Save command to LoKit. - bool sendUnoSave(); + bool sendUnoSave(const bool dontSaveIfUnmodified); /// Saves the document to Storage (assuming LO Core saved to local copy). bool saveToStorage(); diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp index 33e9da9..8a84c8a 100644 --- a/loolwsd/MasterProcessSession.cpp +++ b/loolwsd/MasterProcessSession.cpp @@ -112,12 +112,21 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length) { const std::string stringJSON = stringMsg.substr(index); Poco::JSON::Parser parser; - const auto result = parser.parse(stringJSON); - const auto& object = result.extract<Poco::JSON::Object::Ptr>(); - if (object->get("commandName").toString() == ".uno:Save" && - object->get("success").toString() == "true") + const auto parsedJSON = parser.parse(stringJSON); + const auto& object = parsedJSON.extract<Poco::JSON::Object::Ptr>(); + if (object->get("commandName").toString() == ".uno:Save") { - _docBroker->save(); + bool success = object->get("success").toString() == "true"; + std::string result; + if (object->has("result")) + { + const auto parsedResultJSON = object->get("result"); + const auto& resultObj = parsedResultJSON.extract<Poco::JSON::Object::Ptr>(); + if (resultObj->get("type").toString() == "string") + result = resultObj->get("value").toString(); + } + + _docBroker->save(success, result); return true; } } commit 179990b7f4c7d6a8e16e00e1a981ffdb8f68b7c0 Author: Pranav Kant <[email protected]> Date: Tue Jul 12 15:24:50 2016 +0530 loleaflet: Convert Ctrl + s to .uno:Save Saving this way, key sequences are forwarded to core directly, so loolwsd is not aware if a save operation is going on or not. This leads to problem as loolwsd might want to upload to storage. Change-Id: I32d10012064a0dda7fff0c3ac4848f140b1b6fb8 (cherry picked from commit c9f0f81a1a111c64b69845de56bbb64860243312) diff --git a/loleaflet/src/map/handler/Map.Keyboard.js b/loleaflet/src/map/handler/Map.Keyboard.js index 9202e7a..e75ffed 100644 --- a/loleaflet/src/map/handler/Map.Keyboard.js +++ b/loleaflet/src/map/handler/Map.Keyboard.js @@ -419,6 +419,9 @@ L.Map.Keyboard = L.Handler.extend({ case 80: // p this._map.print(); return true; + case 83: // s + this._map._socket.sendMessage('uno .uno:Save {\"DontTerminateEdit\":{\"type\":\"boolean\",\"value\":true}, \"DontSaveIfUnmodified\":{\"type\":\"boolean\",\"value\":true}}'); + return true; case 86: // v case 118: // v (Safari) return true; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
