[Libreoffice-commits] online.git: 3 commits - loleaflet/src loolwsd/DocumentBroker.cpp loolwsd/DocumentBroker.hpp loolwsd/PrisonerSession.cpp loolwsd/test

Pranav Kant pranavk at collabora.co.uk
Mon Jul 18 06:52:21 UTC 2016


 loleaflet/src/map/handler/Map.Keyboard.js |    3 +
 loolwsd/DocumentBroker.cpp                |   48 ++++++++++++++++++++++++++----
 loolwsd/DocumentBroker.hpp                |    4 +-
 loolwsd/PrisonerSession.cpp               |   19 ++++++++---
 loolwsd/test/UnitAdmin.cpp                |    2 -
 5 files changed, 62 insertions(+), 14 deletions(-)

New commits:
commit da6af8b4ecba56e1bd408eb5a3302e1d35415d6b
Author: Pranav Kant <pranavk at collabora.co.uk>
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

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 2ba777a..d0c21f2 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -188,12 +188,21 @@ 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 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();
@@ -245,7 +254,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)
     {
@@ -265,7 +274,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);
         }
     }
 
@@ -274,7 +283,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;
         }
 
@@ -284,7 +293,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);
@@ -298,7 +307,34 @@ bool DocumentBroker::sendUnoSave()
             _lastFileModifiedTime.fromEpochTime(0);
 
             // We do not want save to terminate editing mode if we are in edit mode now
-            sessionIt.second->sendToInputQueue("uno .uno:Save {\"DontTerminateEdit\":{\"type\":\"boolean\",\"value\":true}}");
+
+            std::ostringstream oss;
+            // arguments init
+            oss << "{";
+
+            // 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());
+            sessionIt.second->sendToInputQueue("uno .uno:Save " + oss.str());
             return true;
         }
     }
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 203775f..a589143 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -156,7 +156,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);
 
@@ -229,7 +229,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/PrisonerSession.cpp b/loolwsd/PrisonerSession.cpp
index 75ba2cf..97fa52b 100644
--- a/loolwsd/PrisonerSession.cpp
+++ b/loolwsd/PrisonerSession.cpp
@@ -79,12 +79,21 @@ bool PrisonerSession::_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 c9f0f81a1a111c64b69845de56bbb64860243312
Author: Pranav Kant <pranavk at collabora.co.uk>
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

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;
commit e6e9236a6a8a13b6cade39e7d04e3fdb1ad7094c
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Jul 14 01:12:46 2016 +0530

    unit-admin: Enable a test
    
    testRmDocNotify was disabled earlier as it seemed to fail
    intermittently. Hopefully, refactoring in
    78876b011d2c3da972ef456a6da2cac08cb0d7d6 and
    4360d31c9e8a3a099d869a9dfd0e2db8a0c03a52 should fix this one too.
    
    Change-Id: I542ca27fab7eb4dfa8ed4a55a7f2eada63e7b96c

diff --git a/loolwsd/test/UnitAdmin.cpp b/loolwsd/test/UnitAdmin.cpp
index edd6bb1..b1f379e 100644
--- a/loolwsd/test/UnitAdmin.cpp
+++ b/loolwsd/test/UnitAdmin.cpp
@@ -404,7 +404,7 @@ public:
         _tests.push_back(&UnitAdmin::testAddDocNotify);
         _tests.push_back(&UnitAdmin::testUsersCount);
         _tests.push_back(&UnitAdmin::testDocCount);
-        // FIXME make this one reliable, and enable again _tests.push_back(&UnitAdmin::testRmDocNotify);
+        _tests.push_back(&UnitAdmin::testRmDocNotify);
         _tests.push_back(&UnitAdmin::testUsersCount);
         _tests.push_back(&UnitAdmin::testDocCount);
     }


More information about the Libreoffice-commits mailing list