tdf#165348: release the lock on original file before clearing URL
Commit 92e7f28f9a (Related: tdf#104718
Use package repair request and behavior, 2023-11-29) made repaired
documents behave like templates, requiring user to explicitly choose
a name on save.
Since switching to template mode happens in this case rather late in
the loading procedure, at this point, lock file is already created
for the original file. Switching to template mode clears media URL;
and after that, media can't remove the lockfile.
This change releases the lock (and removes the lockfile) prior to
clearing URL.
Change-Id: Ibd4794e2b82dc8e1b1c96e22fa2089b9dd597744
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/202521
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
@@ -1300,6 +1300,10 @@ void SfxObjectShell::TemplateDisconnectionAfterLoad()
|
||||
}
|
||||
}
|
||||
|
||||
// tdf#165348: release the lock on the original file before clearing the URL, otherwise
|
||||
// UnlockFile (called later from Close) won't know which lock file to remove.
|
||||
pTmpMedium->UnlockFile(false);
|
||||
|
||||
// set medium to noname
|
||||
pTmpMedium->SetName( OUString(), true );
|
||||
pTmpMedium->Init_Impl();
|
||||
|
||||
@@ -15,6 +15,10 @@ ifneq ($(OS),MACOSX)
|
||||
$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_ooxmlimport2))
|
||||
endif
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_custom_headers,sw_ooxmlimport2,\
|
||||
officecfg/registry \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_add_exception_objects,sw_ooxmlimport2, \
|
||||
sw/qa/extras/ooxmlimport/ooxmlimport2 \
|
||||
))
|
||||
|
||||
Binary file not shown.
@@ -20,14 +20,24 @@
|
||||
|
||||
#include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp>
|
||||
#include <com/sun/star/embed/Aspects.hpp>
|
||||
#include <com/sun/star/frame/XModel.hpp>
|
||||
#include <com/sun/star/task/XInteractionApprove.hpp>
|
||||
#include <com/sun/star/task/XInteractionHandler.hpp>
|
||||
#include <com/sun/star/task/XInteractionRequest.hpp>
|
||||
#include <com/sun/star/text/WritingMode2.hpp>
|
||||
#include <com/sun/star/style/BreakType.hpp>
|
||||
#include <com/sun/star/text/XTextDocument.hpp>
|
||||
#include <com/sun/star/text/XTextTable.hpp>
|
||||
#include <com/sun/star/text/XTextField.hpp>
|
||||
#include <com/sun/star/table/XCellRange.hpp>
|
||||
#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
|
||||
|
||||
#include <comphelper/propertysequence.hxx>
|
||||
#include <comphelper/propertyvalue.hxx>
|
||||
#include <comphelper/scopeguard.hxx>
|
||||
#include <cppuhelper/implbase.hxx>
|
||||
#include <officecfg/Office/Common.hxx>
|
||||
#include <svl/documentlockfile.hxx>
|
||||
#include <vcl/BitmapReadAccess.hxx>
|
||||
#include <vcl/graphicfilter.hxx>
|
||||
#include <xmloff/odffields.hxx>
|
||||
@@ -1436,6 +1446,53 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf169173)
|
||||
CPPUNIT_ASSERT(xServiceInfo->supportsService(u"com.sun.star.text.textfield.DropDown"_ustr));
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(Test, testTdf165348_lockFileOnRepair)
|
||||
{
|
||||
// Enable locking - disabled by default in the test environment
|
||||
auto setConfig = [](bool b) {
|
||||
auto xChanges = comphelper::ConfigurationChanges::create();
|
||||
officecfg::Office::Common::Misc::UseLocking::set(b, xChanges);
|
||||
officecfg::Office::Common::Misc::UseDocumentOOoLockFile::set(b, xChanges);
|
||||
xChanges->commit();
|
||||
};
|
||||
setConfig(true);
|
||||
comphelper::ScopeGuard restoreConfig([&] { setConfig(false); });
|
||||
|
||||
// Copy the broken DOCX to a temp location so the lock file is in a writable temp directory
|
||||
createTempCopy(u"tdf165348_broken_package.docx");
|
||||
OUString aTempURL = maTempFile.GetURL();
|
||||
|
||||
// Interaction handler that auto-approves BrokenPackageRequest (repair dialog)
|
||||
class ApproveRepairHandler : public cppu::WeakImplHelper<task::XInteractionHandler>
|
||||
{
|
||||
public:
|
||||
void SAL_CALL handle(const uno::Reference<task::XInteractionRequest>& xRequest) override
|
||||
{
|
||||
for (auto& xCont : xRequest->getContinuations())
|
||||
{
|
||||
if (auto xApprove = xCont.query<task::XInteractionApprove>())
|
||||
{
|
||||
xApprove->select();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Load with an interaction handler that auto-approves the repair dialog
|
||||
loadFromURL(aTempURL, { comphelper::makePropertyValue(u"InteractionHandler"_ustr,
|
||||
uno::Reference<task::XInteractionHandler>(
|
||||
new ApproveRepairHandler)) });
|
||||
|
||||
// The document should be in repair/template mode, with empty URL
|
||||
CPPUNIT_ASSERT(mxComponent.queryThrow<frame::XModel>()->getURL().isEmpty());
|
||||
|
||||
// The lock file must not remain. Before the fix, the lock was never released; in that scenario,
|
||||
// DocumentLockFile::GetLockData succeeded.
|
||||
CPPUNIT_ASSERT_THROW(svt::DocumentLockFile(aTempURL).GetLockData(),
|
||||
ucb::InteractiveAugmentedIOException);
|
||||
}
|
||||
|
||||
// tests should only be added to ooxmlIMPORT *if* they fail round-tripping in ooxmlEXPORT
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
||||
Reference in New Issue
Block a user