sfx2/source/doc/docfile.cxx | 35 +++++++++++++++++++++++++++++++---- sfx2/source/doc/objstor.cxx | 4 +++- 2 files changed, 34 insertions(+), 5 deletions(-)
New commits: commit 53316a6b8228885a17bf53c4fae6fe9d8ef80d2d Author: Michael Meeks <michael.me...@collabora.com> AuthorDate: Wed Mar 27 18:01:49 2024 +0000 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Thu Mar 28 15:37:46 2024 +0100 lok: avoid perturbing parent background save process' temp file. The temporary file that typically contains the content of thes currently open document is re-written, and deleted on save. Avoid deleting the original when we are background save worker. Change-Id: Ibbb3a963cb3420088623994c067115ff77b96f54 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165408 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index c961733d85ac..ba45c8eb9250 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -76,6 +76,7 @@ #include <tools/fileutil.hxx> #include <unotools/configmgr.hxx> #include <unotools/tempfile.hxx> +#include <comphelper/lok.hxx> #include <comphelper/fileurl.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/propertyvalue.hxx> @@ -344,6 +345,32 @@ CheckReadOnlyTaskTerminateListener::notifyTermination(const css::lang::EventObje lock.unlock(); mCond.notify_one(); } + +/// Temporary file wrapper to handle tmp file lifecyle +/// for lok fork a background saving worker issues. +class MediumTempFile : public ::utl::TempFileNamed +{ + bool m_bWasChild; +public: + MediumTempFile(const OUString *pParent ) + : ::utl::TempFileNamed(pParent) + , m_bWasChild(comphelper::LibreOfficeKit::isForkedChild()) + { + } + + MediumTempFile(const MediumTempFile &rFrom ) = delete; + + ~MediumTempFile() + { + bool isForked = comphelper::LibreOfficeKit::isForkedChild(); + + // avoid deletion of files created by the parent + if (isForked && ! m_bWasChild) + { + EnableKillingFile(false); + } + } +}; } class SfxMedium_Impl @@ -406,7 +433,7 @@ public: uno::Sequence < util::RevisionTag > aVersions; - std::unique_ptr<::utl::TempFileNamed> pTempFile; + std::unique_ptr<MediumTempFile> pTempFile; uno::Reference<embed::XStorage> xStorage; uno::Reference<embed::XStorage> m_xZipStorage; @@ -3524,7 +3551,7 @@ void SfxMedium::CompleteReOpen() bool bUseInteractionHandler = pImpl->bUseInteractionHandler; pImpl->bUseInteractionHandler = false; - std::unique_ptr<::utl::TempFileNamed> pTmpFile; + std::unique_ptr<MediumTempFile> pTmpFile; if ( pImpl->pTempFile ) { pTmpFile = std::move(pImpl->pTempFile); @@ -4035,7 +4062,7 @@ void SfxMedium::CreateTempFile( bool bReplace ) } OUString aLogicBase = GetLogicBase(GetURLObject(), pImpl); - pImpl->pTempFile.reset(new ::utl::TempFileNamed(&aLogicBase)); + pImpl->pTempFile.reset(new MediumTempFile(&aLogicBase)); pImpl->pTempFile->EnableKillingFile(); pImpl->m_aName = pImpl->pTempFile->GetFileName(); OUString aTmpURL = pImpl->pTempFile->GetURL(); @@ -4131,7 +4158,7 @@ void SfxMedium::CreateTempFileNoCopy() pImpl->pTempFile.reset(); OUString aLogicBase = GetLogicBase(GetURLObject(), pImpl); - pImpl->pTempFile.reset(new ::utl::TempFileNamed(&aLogicBase)); + pImpl->pTempFile.reset(new MediumTempFile(&aLogicBase)); pImpl->pTempFile->EnableKillingFile(); pImpl->m_aName = pImpl->pTempFile->GetFileName(); if ( pImpl->m_aName.isEmpty() ) diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 17ee6bf6217d..4d7822613ac9 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -1425,7 +1425,9 @@ bool SfxObjectShell::SaveTo_Impl // TODO/LATER: error handling if( rMedium.GetErrorCode() || pMedium->GetErrorCode() || GetErrorCode() ) { - SAL_WARN("sfx.doc", "SfxObjectShell::SaveTo_Impl: very early error return"); + SAL_WARN("sfx.doc", "SfxObjectShell::SaveTo_Impl: " + " very early error return " << rMedium.GetErrorCode() << " " + << pMedium->GetErrorCode() << " " << GetErrorCode()); return false; }