summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-08-28 09:05:06 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-09-04 10:26:30 +0200
commit24177b61e7839a7b9726aed08997b44d08e89f10 (patch)
treee9f57aadc2a0d74efbcb8846f248de85fa473968
parented3445d862731b57be21a88d8e46b02d055d819b (diff)
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 <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit ff0b1f3c8063f4d7c171a9ea2db4efbff16eda39) Reviewed-on: https://gerrit.libreoffice.org/59760 Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com> Tested-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com> Reviewed-by: Eike Rathke <erack@redhat.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--sfx2/qa/cppunit/test_misc.cxx8
-rw-r--r--sfx2/source/doc/docfile.cxx4
2 files changed, 11 insertions, 1 deletions
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();