bgsave: disable bgsave if we get an error:

Core patch to simulate:

Change-Id: Ifc221a0600956aea1ca67cb690e45b271142845d

--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -2755,7 +2755,7 @@ bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs )
         pMediumTmp->DisableFileSync(true);

     bool bSaved = false;
-    if( !GetErrorIgnoreWarning() && SaveTo_Impl( *pMediumTmp, pArgs ) )
+    if(false) // !GetErrorIgnoreWarning() && SaveTo_Impl( *pMediumTmp, pArgs ) )
     {
         bSaved = true;

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
pull/9099/head
Michael Meeks 2024-05-18 15:54:48 +01:00
parent 00237a3552
commit 6fc853c0f8
3 changed files with 23 additions and 0 deletions

View File

@ -701,6 +701,7 @@ Document::Document(const std::shared_ptr<lok::Office>& loKit,
_websocketHandler(websocketHandler),
_modified(ModifiedState::UnModified),
_isBgSaveProcess(false),
_isBgSaveDisabled(false),
_haveDocPassword(false),
_isDocPasswordProtected(false),
_docPasswordType(DocumentPasswordType::ToView),
@ -1376,6 +1377,12 @@ bool Document::forkToSave(const std::function<void()> &childSave, int viewId)
return false;
}
if (_isBgSaveDisabled)
{
LOG_TRC("Skipping background save for bg save disabled process");
return false;
}
if (!joinThreads())
{
LOG_WRN("Failed to join threads before async save");
@ -2388,6 +2395,12 @@ bool Document::trackDocModifiedState(const std::string &stateChanged)
return filter;
}
void Document::disableBgSave(const std::string &reason)
{
LOG_WRN("Disabled background save " + reason);
_isBgSaveDisabled = true;
}
/// Stops theads, flushes buffers, and exits the process.
void Document::flushAndExit(int code)
{
@ -2421,6 +2434,8 @@ void Document::dumpState(std::ostream& oss)
<< "\n\tinputProcessingEnabled: " << processInputEnabled()
<< "\n\tduringLoad: " << _duringLoad
<< "\n\tmodified: " << toString(_modified)
<< "\n\tbgSaveProc: " << _isBgSaveProcess
<< "\n\tbgSaveDisabled: "<< _isBgSaveDisabled
<< "\n";
// dumpState:

View File

@ -374,6 +374,9 @@ public:
/// Snoop document modified, and return true if filtering notification
bool trackDocModifiedState(const std::string &stateChanged);
/// Permanantly disable background save for this process
void disableBgSave(const std::string &reason);
private:
void postForceModifiedCommand(bool modified);
@ -405,6 +408,7 @@ private:
std::weak_ptr<WebSocketHandler> _saveProcessParent;
ModifiedState _modified;
bool _isBgSaveProcess;
bool _isBgSaveDisabled;
// Document password provided
std::string _docPassword;

View File

@ -249,6 +249,9 @@ void BgSaveParentWebSocketHandler::handleMessage(const std::vector<char>& data)
// Messages already include client-foo prefixes inherited from ourselves
_document->sendFrame(data.data(), data.size(), WSOpCode::Text);
if (tokens[1] == "error:")
_document->disableBgSave("on save error");
// Status update messages are stuck in the bgsave's Idle CallbackFlushHandler
if (tokens[1] == "unocommandresult:")
{
@ -264,6 +267,7 @@ void BgSaveParentWebSocketHandler::handleMessage(const std::vector<char>& data)
{
_document->updateModifiedOnFailedBgSave();
LOG_DBG("Failed to save, not synthesizing modified state");
_document->disableBgSave("on failed save");
}
}
}