common/Util.hpp | 19 +++++++++++++++++++ kit/Kit.cpp | 12 ++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-)
New commits: commit 77e7cae6899728f8a291998eedde7d68bd450504 Author: Ashod Nakashian <[email protected]> AuthorDate: Mon May 27 22:57:53 2019 -0400 Commit: Michael Meeks <[email protected]> CommitDate: Mon Oct 14 21:35:27 2019 +0100 wsd: fix password-protect file loading from multiple views With password-protected files, the first loading attempt always fails due to missing password. At that point the client is notified of the missing password and the user is prompted. The second attempt includes a (hopefully) correct password and the document loading commences. Due to the fact that an exception is raised when the loading fails, this left the loading latch triggered, which blocked subsequent attempts. Change-Id: I7cc257a36eb1cc080f460aac8cdb7030783a5914 diff --git a/common/Util.hpp b/common/Util.hpp index b8b350b2c..d345950ba 100644 --- a/common/Util.hpp +++ b/common/Util.hpp @@ -938,6 +938,25 @@ int main(int argc, char**argv) //// Convert time from ISO8061 fraction format std::chrono::system_clock::time_point iso8601ToTimestamp(const std::string& iso8601Time, const std::string& logName); + /// Automatically execute code at end of current scope. + /// Used for exception-safe code. + class ScopeGuard + { + public: + template <typename T> + explicit ScopeGuard(T const &func) : m_func(func) {} + + ~ScopeGuard() + { + if (m_func) + m_func(); + } + private: + ScopeGuard(const ScopeGuard &) = delete; + ScopeGuard &operator=(const ScopeGuard &) = delete; + + std::function<void()> m_func; + }; } // end namespace Util #endif diff --git a/kit/Kit.cpp b/kit/Kit.cpp index b40577878..60fe9ed81 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -1488,6 +1488,13 @@ private: // Flag and release lock. ++_isLoading; + + Util::ScopeGuard g([this]() { + // Not loading. + --_isLoading; + _cvLoading.notify_one(); + }); + lock.unlock(); try @@ -1495,16 +1502,13 @@ private: if (!load(session, renderOpts, docTemplate)) return false; } - catch (const std::exception& exc) + catch (const std::exception &exc) { LOG_ERR("Exception while loading url [" << uriAnonym << "] for session [" << sessionId << "]: " << exc.what()); return false; } - --_isLoading; - _cvLoading.notify_one(); - return true; } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
