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

2018-09-10 Thread Libreoffice Gerrit user
 sfx2/qa/cppunit/test_misc.cxx |9 +
 sfx2/source/doc/docfile.cxx   |   11 ++-
 2 files changed, 15 insertions(+), 5 deletions(-)

New commits:
commit ec028a73aca92c9d16484d4803852526a1d845a1
Author: Miklos Vajna 
AuthorDate: Mon Sep 3 21:07:00 2018 +0200
Commit: Xisco Faulí 
CommitDate: Mon Sep 10 17:45:01 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/59982
Tested-by: Jenkins
Tested-by: Xisco Faulí 
Reviewed-by: Xisco Faulí 

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(), );
+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(), ) != 0)
+if (lstat(rPath.toUtf8().getStr(), ) != 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
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2018-08-28 Thread Libreoffice Gerrit user
 sfx2/qa/cppunit/test_misc.cxx |8 
 sfx2/source/doc/docfile.cxx   |4 +++-
 2 files changed, 11 insertions(+), 1 deletion(-)

New commits:
commit ff0b1f3c8063f4d7c171a9ea2db4efbff16eda39
Author: Miklos Vajna 
AuthorDate: Tue Aug 28 09:05:06 2018 +0200
Commit: Caolán McNamara 
CommitDate: Tue Aug 28 17:10:14 2018 +0200

tdf#119050 sfx2 store: don't inherit temp file permissions when overwriting

The too aggressive error handling in commit
fb04780cf8523ad4e900ae8b9cecbe7a2697a12a (tdf#116117 sfx2 store: don't
inherit temp file permissions when renaming, 2018-03-12) means that if
the file is already there, then we don't try to stat() it; even if there
is no problem with that.

(cherry picked from commit 38afe2976eea427999c39ee3a73e7938ec8d5f7b)

Change-Id: Ie0b9084064834e339bcae3ad7b4a35c54cb9d3c2
Reviewed-on: https://gerrit.libreoffice.org/59709
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/sfx2/qa/cppunit/test_misc.cxx b/sfx2/qa/cppunit/test_misc.cxx
index d74687b25431..817e246b6bf6 100644
--- a/sfx2/qa/cppunit/test_misc.cxx
+++ b/sfx2/qa/cppunit/test_misc.cxx
@@ -146,6 +146,14 @@ void MiscTest::testNoThumbnail()
 // requested so.
 CPPUNIT_ASSERT(aStatus.getAttributes() & osl_File_Attribute_GrpRead);
 CPPUNIT_ASSERT(aStatus.getAttributes() & osl_File_Attribute_OthRead);
+
+// Now "save as" again to trigger the "overwrite" case.
+xStorable->storeToURL(aTempFile.GetURL(), {});
+CPPUNIT_ASSERT_EQUAL(osl::DirectoryItem::E_None, 
aItem.getFileStatus(aStatus));
+// The following check used to fail in the past, result had temp file
+// permissions.
+CPPUNIT_ASSERT(aStatus.getAttributes() & osl_File_Attribute_GrpRead);
+
 umask(nMask);
 #endif
 
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 72a6c131fc41..2e8b874deedb 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -179,8 +179,10 @@ sal_uInt64 GetDefaultFileAttributes(const OUString& rURL)
 if (!comphelper::isFileUrl(rURL))
 return nRet;
 
+// Make sure the file exists (and create it if not).
 osl::File aFile(rURL);
-if (aFile.open(osl_File_OpenFlag_Create) != osl::File::E_None)
+osl::File::RC nRes = aFile.open(osl_File_OpenFlag_Create);
+if (nRes != osl::File::E_None && nRes != osl::File::E_EXIST)
 return nRet;
 
 aFile.close();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2018-08-10 Thread Libreoffice Gerrit user
 sfx2/qa/cppunit/test_misc.cxx |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

New commits:
commit 7861689c420f38223b8d53dd6911728ea7f26395
Author: Stephan Bergmann 
AuthorDate: Thu Aug 9 13:13:40 2018 +0200
Commit: Christian Lohmaier 
CommitDate: Fri Aug 10 14:37:44 2018 +0200

Set umask /before/ using it

The test used to fail when umask originally was e.g. 077.

Change-Id: I21d346532698feebccc8bb3f6cb9a9dd3002a20e
Reviewed-on: https://gerrit.libreoffice.org/58757
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 
(cherry picked from commit bab5511870e8ad847020645628df8090116f0e8b)
Reviewed-on: https://gerrit.libreoffice.org/58778
Reviewed-by: Christian Lohmaier 

diff --git a/sfx2/qa/cppunit/test_misc.cxx b/sfx2/qa/cppunit/test_misc.cxx
index b7c17a0e1cf3..d74687b25431 100644
--- a/sfx2/qa/cppunit/test_misc.cxx
+++ b/sfx2/qa/cppunit/test_misc.cxx
@@ -119,6 +119,9 @@ void MiscTest::testNoThumbnail()
 CPPUNIT_ASSERT(xComponent.is());
 
 // Save it with the NoThumbnail option and assert that it has no thumbnail.
+#ifndef _WIN32
+mode_t nMask = umask(022);
+#endif
 uno::Reference xStorable(xComponent, uno::UNO_QUERY);
 CPPUNIT_ASSERT(xStorable.is());
 utl::TempFile aTempFile;
@@ -132,7 +135,6 @@ void MiscTest::testNoThumbnail()
 
 #ifndef _WIN32
 // Check permissions of the URL after store.
-mode_t nMask = umask(022);
 osl::DirectoryItem aItem;
 CPPUNIT_ASSERT_EQUAL(osl::DirectoryItem::E_None,
  osl::DirectoryItem::get(aTempFile.GetURL(), aItem));
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits