loleaflet/src/control/Toolbar.js | 4 +++- loleaflet/src/core/Socket.js | 2 +- wsd/ClientSession.cpp | 7 +++++++ wsd/DocumentBroker.cpp | 7 ++++++- wsd/DocumentBroker.hpp | 2 +- wsd/Storage.cpp | 7 ++++++- wsd/Storage.hpp | 6 +++--- wsd/protocol.txt | 8 ++++++++ 8 files changed, 35 insertions(+), 8 deletions(-)
New commits: commit 3528fdc925fd98c7ec9f74c9b7187b73c35aecd9 Author: Pranav Kant <[email protected]> Date: Thu Jun 1 19:46:03 2017 +0530 If user permits, save to storage force-fully in case of doc conflict There is one known problem still - after any user decides to overwrite the file to storage, other users are not informed, so their dialog keeps hanging on the screen until they press the cancel or reload button. Change-Id: I6dad1585e4c53eeed79cd38316892a7f239d44ef (cherry picked from commit 41234773e3b57e1695951bddaedb4f61ad44026d) Reviewed-on: https://gerrit.libreoffice.org/38530 Reviewed-by: Jan Holesovsky <[email protected]> Tested-by: Jan Holesovsky <[email protected]> diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js index 681a8ecc..b5f68749 100644 --- a/loleaflet/src/control/Toolbar.js +++ b/loleaflet/src/control/Toolbar.js @@ -131,7 +131,9 @@ L.Map.include({ }, save: function(dontTerminateEdit, dontSaveIfUnmodified) { - this._socket.sendMessage('save dontTerminateEdit=' + (dontTerminateEdit ? 1 : 0) + ' dontSaveIfUnmodified=' + (dontSaveIfUnmodified ? 1 : 0)); + this._socket.sendMessage('save' + + ' dontTerminateEdit=' + (dontTerminateEdit ? 1 : 0) + + ' dontSaveIfUnmodified=' + (dontSaveIfUnmodified ? 1 : 0)); }, sendUnoCommand: function (command, json) { diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js index 17d73b04..cbb9f523 100644 --- a/loleaflet/src/core/Socket.js +++ b/loleaflet/src/core/Socket.js @@ -369,7 +369,7 @@ L.Socket = L.Class.extend({ this.sendMessage('closedocument'); } else { // They want to overwrite - this.sendMessage('documentconflict.overwrite'); + this.sendMessage('savetostorage force=1'); } }, this) }); diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 84558297..5dd4c278 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -134,6 +134,7 @@ bool ClientSession::_handleInput(const char *buffer, int length) tokens[0] != "resetselection" && tokens[0] != "save" && tokens[0] != "saveas" && + tokens[0] != "savetostorage" && tokens[0] != "selectgraphic" && tokens[0] != "selecttext" && tokens[0] != "setclientpart" && @@ -219,6 +220,12 @@ bool ClientSession::_handleInput(const char *buffer, int length) getTokenInteger(tokens[2], "dontSaveIfUnmodified", dontSaveIfUnmodified); docBroker->sendUnoSave(getId(), dontTerminateEdit != 0, dontSaveIfUnmodified != 0); } + else if (tokens[0] == "savetostorage") + { + int force = 0; + getTokenInteger(tokens[1], "force", force); + docBroker->saveToStorage(getId(), true, "" /* This is irrelevant when success is true*/, true); + } else { if (!filterMessage(firstLine)) diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 2dc938ac..fe01c979 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -542,10 +542,15 @@ bool DocumentBroker::load(const std::shared_ptr<ClientSession>& session, const s } bool DocumentBroker::saveToStorage(const std::string& sessionId, - bool success, const std::string& result) + bool success, const std::string& result, bool force) { assertCorrectThread(); + if (force) + { + LOG_TRC("Document will be saved forcefully to storage."); + _storage->forceSave(); + } const bool res = saveToStorageInternal(sessionId, success, result); // If marked to destroy, or session is disconnected, remove. diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index 5b9b1730..92de36c2 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -240,7 +240,7 @@ public: bool isDocumentChangedInStorage() { return _documentChangedInStorage; } /// Save the document to Storage if it needs persisting. - bool saveToStorage(const std::string& sesionId, bool success, const std::string& result = ""); + bool saveToStorage(const std::string& sesionId, bool success, const std::string& result = "", bool force = false); bool isModified() const { return _isModified; } void setModified(const bool value); diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index f98769c8..341cef41 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -668,13 +668,14 @@ StorageBase::SaveResult WopiStorage::saveLocalFileToStorage(const std::string& a Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, uriObject.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1); request.set("X-WOPI-Override", "PUT"); - if (!_forceOverwrite) + if (!_forceSave) { // Request WOPI host to not overwrite if timestamps mismatch request.set("X-LOOL-WOPI-Timestamp", Poco::DateTimeFormatter::format(Poco::DateTime(_fileInfo._modifiedTime), Poco::DateTimeFormat::ISO8601_FRAC_FORMAT)); } + request.setContentType("application/octet-stream"); request.setContentLength(size); addStorageDebugCookie(request); @@ -699,6 +700,10 @@ StorageBase::SaveResult WopiStorage::saveLocalFileToStorage(const std::string& a const std::string lastModifiedTime = getJSONValue<std::string>(object, "LastModifiedTime"); LOG_TRC("WOPI::PutFile returns LastModifiedTime [" << lastModifiedTime << "]."); _fileInfo._modifiedTime = iso8601ToTimestamp(lastModifiedTime); + + // Reset the force save flag now, if any, since we are done saving + // Next saves shouldn't be saved forcefully unless commanded + _forceSave = false; } else { diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp index 5310ea8e..09002bde 100644 --- a/wsd/Storage.hpp +++ b/wsd/Storage.hpp @@ -78,7 +78,7 @@ public: _jailPath(jailPath), _fileInfo("", "lool", Poco::Timestamp::fromEpochTime(0), 0), _isLoaded(false), - _forceOverwrite(false) + _forceSave(false) { LOG_DBG("Storage ctor: " << uri.toString()); } @@ -92,7 +92,7 @@ public: /// Asks the storage object to force overwrite to storage upon next save /// even if document turned out to be changed in storage - void forceOverwrite() { _forceOverwrite = true; } + void forceSave() { _forceSave = true; } /// Returns the basic information about the file. const FileInfo& getFileInfo() const { return _fileInfo; } @@ -127,7 +127,7 @@ protected: std::string _jailedFilePath; FileInfo _fileInfo; bool _isLoaded; - bool _forceOverwrite; + bool _forceSave; static bool FilesystemEnabled; static bool WopiEnabled; diff --git a/wsd/protocol.txt b/wsd/protocol.txt index 8b5ea409..021dfc35 100644 --- a/wsd/protocol.txt +++ b/wsd/protocol.txt @@ -160,6 +160,14 @@ save dontTerminateEdit=<value> dontSaveIfUnmodified=<value> non-zero. 'dontSaveIfUnmodified' when set to non-zero skips saving the document when it is unmodified. +savetostorage force=<value> + + Saves the files to storage. A 'save' command automatically saves the file to + storage almost always except in the case where there is a document conflict + i.e document in the storage is changed behind our back. We might need to do + call this command with force=1 in that case to forcefully save it to storage + after asking from the user. + clientvisiblearea x=<x> y=<y> width=<width> height=<height> Invokes lok::Document::setClientVisibleArea(). _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
