[Libreoffice-commits] online.git: Branch 'distro/cib/libreoffice-6-2' - 4 commits - configure.ac loleaflet/reference.html loleaflet/src loleaflet/util wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/Storage.cpp wsd/Storage.hpp

Samuel Mehrbrodt (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 1 10:51:20 UTC 2020


 configure.ac                 |    2 +-
 loleaflet/reference.html     |   15 +++++++++------
 loleaflet/src/core/Socket.js |    4 +++-
 loleaflet/util/po2json.py    |    3 +--
 wsd/ClientSession.cpp        |   11 ++---------
 wsd/DocumentBroker.cpp       |   21 ++++++++++++++++++++-
 wsd/DocumentBroker.hpp       |    8 ++++++++
 wsd/Storage.cpp              |    1 +
 wsd/Storage.hpp              |   11 +++++++++++
 9 files changed, 56 insertions(+), 20 deletions(-)

New commits:
commit 62a3682b139066e7490657d9d5cce80c879f2d46
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Wed Jul 1 12:50:40 2020 +0200
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Wed Jul 1 12:50:40 2020 +0200

    Release 6.2.9.0

diff --git a/configure.ac b/configure.ac
index b9d27534e..181a707f4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,7 +3,7 @@
 
 AC_PREREQ([2.63])
 
-AC_INIT([loolwsd], [6.2.8.0], [libreoffice at lists.freedesktop.org])
+AC_INIT([loolwsd], [6.2.9.0], [libreoffice at lists.freedesktop.org])
 LT_INIT([shared, disable-static, dlopen])
 
 AM_INIT_AUTOMAKE([1.10 subdir-objects tar-pax -Wno-portability])
commit d9a8d6cc20a0d8e34d667e7fc2ecfa2b794630ae
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Wed Jul 1 12:46:58 2020 +0200
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Wed Jul 1 12:46:58 2020 +0200

    Report back real save result
    
    665b1629de30a4a402c6b10dd542de158db1f428 was not correct, as it reported back
    the save result of the internal save (which usually succeeds).
    Instead we want to know the save result of the remote storage (WOPI/Webdav).
    So report that back instead.

diff --git a/loleaflet/reference.html b/loleaflet/reference.html
index f087c7464..5dd40dbb1 100644
--- a/loleaflet/reference.html
+++ b/loleaflet/reference.html
@@ -2981,18 +2981,21 @@ Actions response
 		<td><code>
 		    <nobr>success: <boolean></nobr>
 		    <nobr>result: <string></nobr>
+		    <nobr>errorMsg: <string></nobr>
 		</code></td>
 		<td>Acknowledgement when save finishes.<br/>
+		<i>This response is only emitted if <code>Notify</code> parameter
+		is mentioned by <code>Action_Save</code> PostMessage API.</i>
+		<br/>
 		<code>success</code> tells if LOOL was able to save the document
-		successfully. When this is false, then another
-		parameter, <code>result</code> is present which contains the
-		reason that document was not saved.
+		successfully.<br/>
+		<code>result</code> contains the reason the document was not saved.<br/>
 		In case, document was not saved because it was not modified,
 		then this parameter contains the string 'unmodified'. In this
 		case, WOPI hosts can be sure that there are no changes pending
-		in the document to be saved to the storage.
-		This response is only emitted if <code>Notify</code> parameter
-		is mentioned by <code>Action_Save</code> PostMessage API.
+		in the document to be saved to the storage.<br/>
+		<code>errorMsg</code> contains a detailed error message in case saving failed.
+		Probably it will contain the error message returned from the WOPI/Webdav host.
 		</td>
 	</tr>
 </table>
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 4928dc881..8f68b94ad 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -318,7 +318,9 @@ L.Socket = L.Class.extend({
 				}
 
 				var postMessageObj = {
-					success: commandresult['success']
+					success: commandresult['success'],
+					result: commandresult['result'],
+					errorMsg: commandresult['errorMsg']
 				};
 				this._map.fire('postMessage', {msgId: 'Action_Save_Resp', args: postMessageObj});
 			}
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 03a439054..262abe6ab 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -267,11 +267,7 @@ bool ClientSession::_handleInput(const char *buffer, int length)
         if (!isReadOnly() && tokens.size() > 2)
             getTokenInteger(tokens[2], "dontSaveIfUnmodified", dontSaveIfUnmodified);
 
-        bool result = docBroker->sendUnoSave(getId(), dontTerminateEdit != 0, dontSaveIfUnmodified != 0);
-
-        std::string resultstr = result ? "true" : "false";
-        std::string msg = "commandresult: { \"command\": \"save\", \"success\": " + resultstr + " }";
-        docBroker->broadcastMessage(msg);
+        docBroker->sendUnoSave(getId(), dontTerminateEdit != 0, dontSaveIfUnmodified != 0);
     }
     else if (tokens[0] == "savetostorage")
     {
@@ -279,10 +275,7 @@ bool ClientSession::_handleInput(const char *buffer, int length)
         if (tokens.size() > 1)
             getTokenInteger(tokens[1], "force", force);
 
-        bool result = docBroker->saveToStorage(getId(), true, "" /* This is irrelevant when success is true*/, true);
-        std::string resultstr = result ? "true" : "false";
-        std::string msg = "commandresult: { \"command\": \"savetostorage\", \"success\": " + resultstr + " }";
-        docBroker->broadcastMessage(msg);
+        docBroker->saveToStorage(getId(), true, "" /* This is irrelevant when success is true*/, true);
     }
     else if (tokens[0] == "clientvisiblearea")
     {
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 61691133f..a6e92498d 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -783,6 +783,7 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
         LOG_DBG("Save skipped as document [" << _docKey << "] was not modified.");
         _lastSaveTime = std::chrono::steady_clock::now();
         _poll->wakeup();
+        broadcastSaveResult(true, "unmodified");
         return true;
     }
 
@@ -790,6 +791,7 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
     if (it == _sessions.end())
     {
         LOG_ERR("Session with sessionId [" << sessionId << "] not found while saving docKey [" << _docKey << "].");
+        broadcastSaveResult(false, "Session not found");
         return false;
     }
 
@@ -798,6 +800,7 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
     {
         LOG_ERR("Cannot save docKey [" << _docKey << "], the .uno:Save has failed in LOK.");
         it->second->sendTextFrame("error: cmd=storage kind=savefailed");
+        broadcastSaveResult(false, "unmodified");
         return false;
     }
 
@@ -821,6 +824,7 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
         LOG_DBG("Skipping unnecessary saving to URI [" << uriAnonym << "] with docKey [" << _docKey <<
                 "]. File last modified " << _lastFileModifiedTime.elapsed() / 1000000 << " seconds ago.");
         _poll->wakeup();
+        broadcastSaveResult(true, "unmodified");
         return true;
     }
 
@@ -870,7 +874,7 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
             LOG_DBG("Saved As docKey [" << _docKey << "] to URI [" << LOOLWSD::anonymizeUrl(url) <<
                     "] with name [" << filenameAnonym << "] successfully.");
         }
-
+        broadcastSaveResult(true);
         return true;
     }
     else if (storageSaveResult.getResult() == StorageBase::SaveResult::DISKFULL)
@@ -884,18 +888,21 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
             sessionIt.second->setReadOnly();
             sessionIt.second->sendTextFrame("error: cmd=storage kind=savediskfull");
         }
+        broadcastSaveResult(false, "Disk full", storageSaveResult.getErrorMsg());
     }
     else if (storageSaveResult.getResult() == StorageBase::SaveResult::UNAUTHORIZED)
     {
         LOG_ERR("Cannot save docKey [" << _docKey << "] to storage URI [" << uriAnonym <<
                 "]. Invalid or expired access token. Notifying client.");
         it->second->sendTextFrame("error: cmd=storage kind=saveunauthorized");
+        broadcastSaveResult(false, "Invalid or expired access token", storageSaveResult.getErrorMsg());
     }
     else if (storageSaveResult.getResult() == StorageBase::SaveResult::FAILED)
     {
         //TODO: Should we notify all clients?
         LOG_ERR("Failed to save docKey [" << _docKey << "] to URI [" << uriAnonym << "]. Notifying client.");
         it->second->sendTextFrame("error: cmd=storage kind=savefailed");
+        broadcastSaveResult(false, "Save failed", storageSaveResult.getErrorMsg());
     }
     else if (storageSaveResult.getResult() == StorageBase::SaveResult::DOC_CHANGED)
     {
@@ -906,11 +913,23 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
             message = "error: cmd=storage kind=documentconflict";
 
         broadcastMessage(message);
+        broadcastSaveResult(false, "Conflict: Document changed in storage", storageSaveResult.getErrorMsg());
     }
 
     return false;
 }
 
+void DocumentBroker::broadcastSaveResult(bool success, const std::string& result, const std::string& errorMsg)
+{
+    std::string resultstr = success ? "true" : "false";
+    // Some sane limit, otherwise we get problems transfering this to the client with large strings (can be a whole webpage)
+    std::string errorMsgFormatted = errorMsg.substr(0, 1000);
+    // Replace reserverd characters
+    errorMsgFormatted = Poco::translate(errorMsgFormatted, "\"", "'");
+    broadcastMessage("commandresult: { \"command\": \"save\", \"success\": " + resultstr +
+                     ", \"result\": \"" + result + "\", \"errorMsg\": \"" + errorMsgFormatted  + "\"}");
+}
+
 void DocumentBroker::setLoaded()
 {
     if (!_isLoaded)
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index b2c7543ba..e0a3480e7 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -372,6 +372,14 @@ private:
     /// Saves the doc to the storage.
     bool saveToStorageInternal(const std::string& sesionId, bool success, const std::string& result = "", const std::string& saveAsPath = std::string(), const std::string& saveAsFilename = std::string());
 
+    /**
+     * Report back the save result to PostMessage users (Action_Save_Resp)
+     * @param success: Whether saving was successful
+     * @param result: Short message why saving was (not) successful
+     * @param errorMsg: Long error msg (Error message from WOPI host if any)
+     */
+    void broadcastSaveResult(bool success, const std::string& result = "", const std::string& errorMsg = "");
+
     /// True iff a save is in progress (requested but not completed).
     bool isSaving() const { return _lastSaveResponseTime < _lastSaveRequestTime; }
 
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index 3b36ef7d7..9f195cb9d 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -778,6 +778,7 @@ StorageBase::SaveResult WopiStorage::saveLocalFileToStorage(const Authorization&
         std::ostringstream oss;
         Poco::StreamCopier::copyStream(rs, oss);
         std::string responseString = oss.str();
+        saveResult.setErrorMsg(responseString);
 
         const std::string wopiLog(isSaveAs ? "WOPI::PutRelativeFile" : "WOPI::PutFile");
 
diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp
index 67cda1dfb..23781376b 100644
--- a/wsd/Storage.hpp
+++ b/wsd/Storage.hpp
@@ -97,10 +97,21 @@ public:
             return _saveAsUrl;
         }
 
+        void setErrorMsg(const std::string &msg)
+        {
+            _errorMsg = msg;
+        }
+
+        const std::string &getErrorMsg() const
+        {
+            return _errorMsg;
+        }
+
     private:
         Result _result;
         std::string _saveAsName;
         std::string _saveAsUrl;
+        std::string _errorMsg;
     };
 
     enum class LOOLStatusCode
commit 11bb5aeceaf4f239f75bafb3f6481bd6ed1d2437
Author:     Andras Timar <andras.timar at collabora.com>
AuthorDate: Wed Oct 30 19:16:11 2019 +0100
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Wed Jul 1 08:26:28 2020 +0200

    typo
    
    Change-Id: Iaa986b700fecb10561d03008c291c9a7bf9df244
    (cherry picked from commit e0f8001e3a439250fd51ba4c00f5b44627ed8e6c)

diff --git a/loleaflet/util/po2json.py b/loleaflet/util/po2json.py
index 6c35db1db..a3284573b 100755
--- a/loleaflet/util/po2json.py
+++ b/loleaflet/util/po2json.py
@@ -1,4 +1,4 @@
-+#!/usr/bin/env python3
+#!/usr/bin/env python3
 #
 # convert .po to .json
 #
commit 90af72a5a527011625ebef1f674ae8a7c1ace0f5
Author:     Andras Timar <andras.timar at collabora.com>
AuthorDate: Wed Oct 30 19:12:40 2019 +0100
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Wed Jul 1 08:26:20 2020 +0200

    Use Python 3 for loleaflet/util/po2json.py, too
    
    Change-Id: I8f7aec078fba975eb516a497c1a287ed6a37e9e1
    (cherry picked from commit 4a589e90b2938d2b121dc7086044fbb7d6d3525b)

diff --git a/loleaflet/util/po2json.py b/loleaflet/util/po2json.py
index cfcb45e26..6c35db1db 100755
--- a/loleaflet/util/po2json.py
+++ b/loleaflet/util/po2json.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
++#!/usr/bin/env python3
 #
 # convert .po to .json
 #
@@ -58,4 +58,3 @@ for srcfile in args:
 	dest.write(json.dumps(xlate_map, sort_keys = True));
 
 	dest.close()
-


More information about the Libreoffice-commits mailing list