[Libreoffice-commits] core.git: Branch 'libreoffice-6-1-1' - sfx2/qa sfx2/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Sep 10 20:06:31 UTC 2018


 sfx2/qa/cppunit/test_misc.cxx |    9 +++++++++
 sfx2/source/doc/docfile.cxx   |   11 ++++++-----
 2 files changed, 15 insertions(+), 5 deletions(-)

New commits:
commit c51a113b30d02e51f16484faa2550d56880f453b
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Mon Sep 3 21:07:00 2018 +0200
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Mon Sep 10 22:06:08 2018 +0200

    tdf#119381 sfx2 store: don't break symlink targets
    
    osl::File::move() would not follow symlinks for the target, so don't
    move the file in that case.
    
    (cherry picked from commit 72be5ac08aa963bdd42d2e56a62f43e69f728caa)
    
    Change-Id: I907e1ba8db04dad670c884ea0283947f953117da
    Reviewed-on: https://gerrit.libreoffice.org/60272
    Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sfx2/qa/cppunit/test_misc.cxx b/sfx2/qa/cppunit/test_misc.cxx
index 817e246b6bf6..ffe23997c12a 100644
--- a/sfx2/qa/cppunit/test_misc.cxx
+++ b/sfx2/qa/cppunit/test_misc.cxx
@@ -186,6 +186,15 @@ void MiscTest::testHardLinks()
     // This failed: hard link count was 1, the hard link broke on store.
     CPPUNIT_ASSERT(buf.st_nlink > 1);
 
+    // Test that symlinks are presreved as well.
+    remove(aNew.getStr());
+    symlink(aOld.getStr(), aNew.getStr());
+    xStorable->storeToURL(aURL + ".2", {});
+    nRet = lstat(aNew.getStr(), &buf);
+    CPPUNIT_ASSERT_EQUAL(0, nRet);
+    // This failed, the hello.odt.2 symlink was replaced with a real file.
+    CPPUNIT_ASSERT(bool(S_ISLNK(buf.st_mode)));
+
     xComponent->dispose();
 #endif
 }
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 2e8b874deedb..e6a858ae6bf8 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -199,8 +199,8 @@ sal_uInt64 GetDefaultFileAttributes(const OUString& rURL)
     return nRet;
 }
 
-/// Determines if rURL is a non-hard-linked file:// URL.
-bool IsNotHardLinkedFile(const OUString& rURL)
+/// Determines if rURL is a non-linked (symlink or hardlink) file:// URL.
+bool IsNotLinkedFile(const OUString& rURL)
 {
     if (!comphelper::isFileUrl(rURL))
         return false;
@@ -211,10 +211,11 @@ bool IsNotHardLinkedFile(const OUString& rURL)
         return false;
 
     struct stat buf;
-    if (stat(rPath.toUtf8().getStr(), &buf) != 0)
+    if (lstat(rPath.toUtf8().getStr(), &buf) != 0)
         return false;
 
-    if (buf.st_nlink > 1)
+    // Hardlink or symlink: osl::File::move() doesn't play with these nicely.
+    if (buf.st_nlink > 1 || S_ISLNK(buf.st_mode))
         return false;
 #endif
 
@@ -1851,7 +1852,7 @@ void SfxMedium::TransactedTransferForFS_Impl( const INetURLObject& aSource,
                 OUString aDestMainURL = aDest.GetMainURL(INetURLObject::DecodeMechanism::NONE);
 
                 sal_uInt64 nAttributes = GetDefaultFileAttributes(aDestMainURL);
-                if (IsNotHardLinkedFile(aDestMainURL) && osl::File::move(aSourceMainURL, aDestMainURL) == osl::FileBase::E_None)
+                if (IsNotLinkedFile(aDestMainURL) && osl::File::move(aSourceMainURL, aDestMainURL) == osl::FileBase::E_None)
                 {
                     if (nAttributes)
                         // Adjust attributes, source might be created with


More information about the Libreoffice-commits mailing list