[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-4-0' - 2 commits - loolwsd.xml.in wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp
Ashod Nakashian (via logerrit)
logerrit at kemper.freedesktop.org
Tue Oct 22 17:23:49 UTC 2019
loolwsd.xml.in | 1
wsd/DocumentBroker.cpp | 52 +++++++++++++++++++++++++++++++------------------
wsd/DocumentBroker.hpp | 9 ++++++--
wsd/LOOLWSD.cpp | 1
4 files changed, 42 insertions(+), 21 deletions(-)
New commits:
commit f2913f20b03e916ce8a70f927ca3f5655a3768a8
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Tue Oct 22 10:28:57 2019 -0400
Commit: Andras Timar <andras.timar at collabora.com>
CommitDate: Tue Oct 22 19:23:44 2019 +0200
wsd: upload to storage when per_document.always_save_on_exit is set
Saving the document on exit is not enough, we also need
to send it to the storage. We now force doing that,
even when there is no modifiction to the document
(i.e. a new version wasn't really saved).
Change-Id: Ic4e1b1424f32d3141e98c936a51e47c9e4b9f753
Reviewed-on: https://gerrit.libreoffice.org/81336
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 9c35e4de1..6650593b7 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -774,13 +774,20 @@ bool DocumentBroker::saveToStorage(const std::string& sessionId,
{
assertCorrectThread();
- if (force)
+ // Force saving on exit, if enabled.
+ if (!force && isMarkedToDestroy())
{
- LOG_TRC("Document will be saved forcefully to storage.");
- _storage->forceSave();
+ static const bool always_save = LOOLWSD::getConfigValue<bool>("per_document.always_save_on_exit", false);
+ if (always_save)
+ {
+ LOG_TRC("Enabling forced saving to storage per always_save_on_exit config.");
+ force = true;
+ }
}
- const bool res = saveToStorageInternal(sessionId, success, result);
+ constexpr bool isRename = false;
+ const bool res = saveToStorageInternal(sessionId, success, result, /*saveAsPath*/ std::string(),
+ /*saveAsFilename*/ std::string(), isRename, force);
// If marked to destroy, or session is disconnected, remove.
const auto it = _sessions.find(sessionId);
@@ -804,22 +811,21 @@ bool DocumentBroker::saveAsToStorage(const std::string& sessionId, const std::st
return saveToStorageInternal(sessionId, true, "", saveAsPath, saveAsFilename, isRename);
}
-bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
- bool success, const std::string& result,
- const std::string& saveAsPath, const std::string& saveAsFilename, const bool isRename)
+bool DocumentBroker::saveToStorageInternal(const std::string& sessionId, bool success,
+ const std::string& result, const std::string& saveAsPath,
+ const std::string& saveAsFilename, const bool isRename,
+ const bool force)
{
assertCorrectThread();
// Record that we got a response to avoid timeing out on saving.
_lastSaveResponseTime = std::chrono::steady_clock::now();
- const bool isSaveAs = !saveAsPath.empty();
-
// If save requested, but core didn't save because document was unmodified
// notify the waiting thread, if any.
- LOG_TRC("Saving to storage docKey [" << _docKey << "] for session [" << sessionId <<
- "]. Success: " << success << ", result: " << result);
- if (!success && result == "unmodified" && !isRename)
+ LOG_TRC("Uploading to storage docKey [" << _docKey << "] for session [" << sessionId <<
+ "]. Success: " << success << ", result: " << result << ", force: " << force);
+ if (!success && result == "unmodified" && !isRename && !force)
{
LOG_DBG("Save skipped as document [" << _docKey << "] was not modified.");
_lastSaveTime = std::chrono::steady_clock::now();
@@ -830,18 +836,24 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
const auto it = _sessions.find(sessionId);
if (it == _sessions.end())
{
- LOG_ERR("Session with sessionId [" << sessionId << "] not found while saving docKey [" << _docKey << "].");
+ LOG_ERR("Session with sessionId [" << sessionId << "] not found while storing document docKey [" << _docKey << "]. The document ");
return false;
}
// Check that we are actually about to upload a successfully saved document.
- if (!success)
+ if (!success && !force)
{
- LOG_ERR("Cannot save docKey [" << _docKey << "], the .uno:Save has failed in LOK.");
+ LOG_ERR("Cannot store docKey [" << _docKey << "] as .uno:Save has failed in LOK.");
it->second->sendTextFrame("error: cmd=storage kind=savefailed");
return false;
}
+ if (force)
+ {
+ LOG_DBG("Document docKey [" << _docKey << "] will be saved forcefully to storage.");
+ }
+
+ const bool isSaveAs = !saveAsPath.empty();
const Authorization auth = it->second->getAuthorization();
const std::string uri = isSaveAs ? saveAsPath : it->second->getPublicUri().toString();
@@ -1215,14 +1227,14 @@ size_t DocumentBroker::removeSession(const std::string& id)
_markToDestroy = (_sessions.size() <= 1);
const bool lastEditableSession = !it->second->isReadOnly() && !haveAnotherEditableSession(id);
+ static const bool dontSaveIfUnmodified = !LOOLWSD::getConfigValue<bool>("per_document.always_save_on_exit", false);
LOG_INF("Removing session ["
<< id << "] on docKey [" << _docKey << "]. Have " << _sessions.size()
<< " sessions. IsReadOnly: " << it->second->isReadOnly() << ", IsViewLoaded: "
<< it->second->isViewLoaded() << ". markToDestroy: " << _markToDestroy
- << ", LastEditableSession: " << lastEditableSession);
-
- const auto dontSaveIfUnmodified = !LOOLWSD::getConfigValue<bool>("per_document.always_save_on_exit", false);
+ << ", LastEditableSession: " << lastEditableSession
+ << ", dontSaveIfUnmodified: " << dontSaveIfUnmodified);
// If last editable, save and don't remove until after uploading to storage.
if (!lastEditableSession || !autoSave(isPossiblyModified(), dontSaveIfUnmodified))
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 9a00635b0..1a8b9c8dd 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -376,7 +376,11 @@ private:
void terminateChild(const std::string& closeReason);
/// 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(), const bool isRename = false);
+ bool saveToStorageInternal(const std::string& sesionId, bool success,
+ const std::string& result = std::string(),
+ const std::string& saveAsPath = std::string(),
+ const std::string& saveAsFilename = std::string(),
+ const bool isRename = false, const bool force = false);
/// True iff a save is in progress (requested but not completed).
bool isSaving() const { return _lastSaveResponseTime < _lastSaveRequestTime; }
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 690ae41e5..ba9a6f94f 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -805,6 +805,7 @@ void LOOLWSD::initialize(Application& self)
{ "net.proto", "all" },
{ "net.service_root", "" },
{ "num_prespawn_children", "1" },
+ { "per_document.always_save_on_exit", "false" },
{ "per_document.autosave_duration_secs", "300" },
{ "per_document.document_signing_url", VEREIGN_URL },
{ "per_document.idle_timeout_secs", "3600" },
commit db1c49b65984ffac0265be76ae54533b8be2b17a
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Jun 6 11:48:54 2019 +0200
Commit: Andras Timar <andras.timar at collabora.com>
CommitDate: Tue Oct 22 19:23:29 2019 +0200
wsd: add new always_save_on_exit config option
The default behavior is unchanged: once the last editor exits, we still
only perform a save when the document is modified.
It's possible to opt in for the new behavior, though: in that case the
save after the exit of the last editor will happen even for unmodified
documents.
Change-Id: I14c17035a932cf952217f3b71fdef57fede0ce24
Reviewed-on: https://gerrit.libreoffice.org/81260
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
diff --git a/loolwsd.xml.in b/loolwsd.xml.in
index e3f2e9e29..faf305e5e 100644
--- a/loolwsd.xml.in
+++ b/loolwsd.xml.in
@@ -24,6 +24,7 @@
<!-- They are disabled when the value is zero or negative. -->
<idlesave_duration_secs desc="The number of idle seconds after which document, if modified, should be saved. Defaults to 30 seconds." type="int" default="30">30</idlesave_duration_secs>
<autosave_duration_secs desc="The number of seconds after which document, if modified, should be saved. Defaults to 5 minutes." type="int" default="300">300</autosave_duration_secs>
+ <always_save_on_exit desc="On exiting the last editor, always perform the save, even if the document is not modified." type="bool" default="false">false</always_save_on_exit>
<limit_virt_mem_kb desc="The maximum virtual memory allowed to each document process. 0 for unlimited, 1700 min." type="uint">0</limit_virt_mem_kb>
<limit_data_mem_kb desc="The maximum memory data segment allowed to each document process. 0 for unlimited." type="uint">0</limit_data_mem_kb>
<limit_stack_mem_kb desc="The maximum stack size allowed to each document process. 0 for unlimited." type="uint">8000</limit_stack_mem_kb>
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 0c423bc52..9c35e4de1 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -980,7 +980,7 @@ void DocumentBroker::setLoaded()
}
}
-bool DocumentBroker::autoSave(const bool force)
+bool DocumentBroker::autoSave(const bool force, const bool dontSaveIfUnmodified)
{
assertCorrectThread();
@@ -1025,7 +1025,7 @@ bool DocumentBroker::autoSave(const bool force)
// triggered when the document is closed. In the case of network disconnection or browser crash
// most users would want to have had the chance to hit save before the document unloaded.
sent = sendUnoSave(savingSessionId, /*dontTerminateEdit=*/true,
- /*dontSaveIfUnmodified=*/true, /*isAutosave=*/false,
+ dontSaveIfUnmodified, /*isAutosave=*/false,
/*isExitSave=*/true);
}
else if (_isModified)
@@ -1222,8 +1222,10 @@ size_t DocumentBroker::removeSession(const std::string& id)
<< it->second->isViewLoaded() << ". markToDestroy: " << _markToDestroy
<< ", LastEditableSession: " << lastEditableSession);
+ const auto dontSaveIfUnmodified = !LOOLWSD::getConfigValue<bool>("per_document.always_save_on_exit", false);
+
// If last editable, save and don't remove until after uploading to storage.
- if (!lastEditableSession || !autoSave(isPossiblyModified()))
+ if (!lastEditableSession || !autoSave(isPossiblyModified(), dontSaveIfUnmodified))
removeSessionInternal(id);
}
catch (const std::exception& ex)
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index b358dba80..9a00635b0 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -254,9 +254,10 @@ public:
/// Save the document if the document is modified.
/// @param force when true, will force saving if there
/// has been any recent activity after the last save.
+ /// @param dontSaveIfUnmodified when true, save will fail if the document is not modified.
/// @return true if attempts to save or it also waits
/// and receives save notification. Otherwise, false.
- bool autoSave(const bool force);
+ bool autoSave(const bool force, const bool dontSaveIfUnmodified = true);
Poco::URI getPublicUri() const { return _uriPublic; }
const std::string& getJailId() const { return _jailId; }
More information about the Libreoffice-commits
mailing list