summaryrefslogtreecommitdiff
path: root/sw/qa/extras
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-05-14 21:47:10 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-05-15 09:06:59 +0200
commitc1676204447df942e766c0780c1580e1f0427b73 (patch)
tree4c91184869ef1aa291b4408aee14b724934ee8c5 /sw/qa/extras
parentb64ef8d113c1cc05c07b3d9fa25e34c7a98acf4a (diff)
tdf#117225 sfx2: fix leftover temp file when saving doc with embedded objects
Regression from 27938e1bbd5f3405c47b9933be7489eeb03920f3 (sfx2 store: create temp files next to local files (storage case), 2018-01-17), the optimization to store temp files during save next to the destination document (so that it can be renamed and not copied after writing the data successfully) causes problems when we have embedded objects. Avoid the problem by disabling this new optimization when the document has embedded objects. How to fix the actual root cause is not clear to me, I see that: - the SfxMedium::GetOutputStorage() call in SfxObjectShell::SaveTo_Impl() create a temp file - the SfxMedium::Commit() call in SfxObjectShell::SaveTo_Impl() tries to remove the file, which fails on Windows as there is an open file handle to that file - SfxObjectShell::SwitchChildrenPersistance() would close the storage, owning that open file handle, but it's too late So just go back to the previous behavior for now. Change-Id: I37259100d1ddf963c1f2d3b7bd9f460bc995815c Reviewed-on: https://gerrit.libreoffice.org/54340 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sw/qa/extras')
-rw-r--r--sw/qa/extras/uiwriter/data/tdf117225.odtbin0 -> 11015 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx43
2 files changed, 42 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/data/tdf117225.odt b/sw/qa/extras/uiwriter/data/tdf117225.odt
new file mode 100644
index 000000000000..9e31eb6b2090
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf117225.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 735bbe8f7cd0..2d4aa322db4c 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -120,7 +120,29 @@
#include <iodetect.hxx>
#include <wrthtml.hxx>
-static char const DATA_DIRECTORY[] = "/sw/qa/extras/uiwriter/data/";
+namespace
+{
+char const DATA_DIRECTORY[] = "/sw/qa/extras/uiwriter/data/";
+
+int CountFilesInDirectory(const OUString &rURL)
+{
+ int nRet = 0;
+
+ osl::Directory aDir(rURL);
+ CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, aDir.open());
+
+ osl::DirectoryItem aItem;
+ osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL|osl_FileStatus_Mask_Type);
+ while (aDir.getNextItem(aItem) == osl::FileBase::E_None)
+ {
+ aItem.getFileStatus(aFileStatus);
+ if (aFileStatus.getFileType() != osl::FileStatus::Directory)
+ ++nRet;
+ }
+
+ return nRet;
+}
+}
class SwUiWriterTest : public SwModelTestBase, public HtmlTestTools
{
@@ -319,6 +341,7 @@ public:
void testTdf116403();
void testHtmlCopyImages();
void testTdf116789();
+ void testTdf117225();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
@@ -511,6 +534,7 @@ public:
CPPUNIT_TEST(testTdf116403);
CPPUNIT_TEST(testHtmlCopyImages);
CPPUNIT_TEST(testTdf116789);
+ CPPUNIT_TEST(testTdf117225);
CPPUNIT_TEST_SUITE_END();
private:
@@ -6191,6 +6215,23 @@ void SwUiWriterTest::testTdf116789()
CPPUNIT_ASSERT_EQUAL(xText1, xText2);
}
+void SwUiWriterTest::testTdf117225()
+{
+ // Test that saving a document with an embedded object does not leak
+ // tempfiles in the directory of the target file.
+ OUString aTargetDirectory = m_directories.getURLFromWorkdir("/CppunitTest/sw_uiwriter.test.user/");
+ OUString aTargetFile = aTargetDirectory + "tdf117225.odt";
+ OUString aSourceFile = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf117225.odt";
+ osl::File::copy(aSourceFile, aTargetFile);
+ mxComponent = loadFromDesktop(aTargetFile);
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ int nExpected = CountFilesInDirectory(aTargetDirectory);
+ xStorable->store();
+ int nActual = CountFilesInDirectory(aTargetDirectory);
+ // nActual was nExpected + 1, i.e. we leaked a tempfile.
+ CPPUNIT_ASSERT_EQUAL(nExpected, nActual);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();