diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-03-26 10:40:52 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-03-26 17:40:28 +0200 |
commit | 546ed01e62c9a36a675c7390371aaec7f1647a33 (patch) | |
tree | 2d0c9f0e49b3512b0a3431d501f87a820fa83cb6 /sfx2/qa | |
parent | 5e18136a01208f5df7c5f554bbcdab2ef661e136 (diff) |
sfx2 store: avoid rename() for files with >1 hard link count
Rename would break the hard link; in practice e.g. Online's 'make run'
debug feature depends on not breaking hardlinks.
Change-Id: Id3ac19493b6b473274b7ed53a4ca06fc34bc1668
Reviewed-on: https://gerrit.libreoffice.org/51858
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sfx2/qa')
-rw-r--r-- | sfx2/qa/cppunit/test_misc.cxx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/sfx2/qa/cppunit/test_misc.cxx b/sfx2/qa/cppunit/test_misc.cxx index a1ecc01a7c61..72f21fc66c3a 100644 --- a/sfx2/qa/cppunit/test_misc.cxx +++ b/sfx2/qa/cppunit/test_misc.cxx @@ -11,6 +11,7 @@ #ifndef _WIN32 #include <sys/stat.h> +#include <unistd.h> #endif #include <memory> @@ -51,6 +52,7 @@ public: virtual void setUp() override; void testODFCustomMetadata(); void testNoThumbnail(); + void testHardLinks(); virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override { @@ -66,6 +68,7 @@ public: CPPUNIT_TEST_SUITE(MiscTest); CPPUNIT_TEST(testODFCustomMetadata); CPPUNIT_TEST(testNoThumbnail); + CPPUNIT_TEST(testHardLinks); CPPUNIT_TEST_SUITE_END(); private: @@ -147,6 +150,35 @@ void MiscTest::testNoThumbnail() xComponent->dispose(); } +void MiscTest::testHardLinks() +{ +#ifndef _WIN32 + OUString aSourceDir = m_directories.getURLFromSrc("/sfx2/qa/cppunit/misc/"); + OUString aTargetDir = m_directories.getURLFromWorkdir("/CppunitTest/sfx2_misc.test.user/"); + const OUString aURL(aTargetDir + "hello.odt"); + osl::File::copy(aSourceDir + "hello.odt", aURL); + OUString aTargetPath; + osl::FileBase::getSystemPathFromFileURL(aURL, aTargetPath); + OString aOld = aTargetPath.toUtf8(); + aTargetPath += ".2"; + OString aNew = aTargetPath.toUtf8(); + link(aOld.getStr(), aNew.getStr()); + + uno::Reference<lang::XComponent> xComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument"); + CPPUNIT_ASSERT(xComponent.is()); + + uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY); + xStorable->store(); + + struct stat buf; + stat(aOld.getStr(), &buf); + // This failed: hard link count was 1, the hard link broke on store. + CPPUNIT_ASSERT(buf.st_nlink > 1); + + xComponent->dispose(); +#endif +} + CPPUNIT_TEST_SUITE_REGISTRATION(MiscTest); } |