wsd: verify that the last-editing-session can save

The last-editing-session could still be valid, but
waiting disconnection, in which case the kit might
have already discarded it, and so saving would
fail (silently, and thereby leaving docbroker
waiting for the save response).

To avoid this, we always validate the
last-editing-session before using, and not just
when setting it.

Change-Id: I60cd219d8e5a9945396110c8f8d194e87f81afba
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit e1fc6adbfef7ee0678c7a563fd6142c32f2da4a6)
This commit is contained in:
Ashod Nakashian 2021-08-26 08:05:29 -04:00 committed by Ashod Nakashian
parent b82b18e8c9
commit 965e5cb37d

View file

@ -1749,9 +1749,13 @@ bool DocumentBroker::autoSave(const bool force, const bool dontSaveIfUnmodified)
// Which session to use when auto saving ?
// Prefer the last editing view, if still valid, otherwise, find the first writable sessionId.
const std::string savingSessionId = (_sessions.find(_lastEditingSessionId) != _sessions.end())
? _lastEditingSessionId
: getWriteableSessionId();
// Note: a loaded view cannot be disconnecting.
const auto itLastEditingSession = _sessions.find(_lastEditingSessionId);
const std::string savingSessionId =
(itLastEditingSession != _sessions.end() && itLastEditingSession->second->isReadOnly() &&
itLastEditingSession->second->isViewLoaded())
? _lastEditingSessionId
: getWriteableSessionId();
// Remember the last save time, since this is the predicate.
LOG_TRC("Checking to autosave [" << _docKey << "] using session [" << savingSessionId << ']');