tdf#119050 sfx2 store: don't inherit temp file permissions when overwriting
authorMiklos Vajna <vmiklos@collabora.co.uk>
Tue, 28 Aug 2018 07:05:06 +0000 (09:05 +0200)
committerRene Engelhard <rene@debian.org>
Fri, 31 Aug 2018 10:45:39 +0000 (11:45 +0100)
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>
Gbp-Pq: Name do-not-reset-permissions-on-save.diff

sfx2/qa/cppunit/test_misc.cxx
sfx2/source/doc/docfile.cxx

index d74687b25431fb3ed919fa9a2cb3663e67b08da9..817e246b6bf6d4d30d4226a06c774c2e75913c00 100644 (file)
@@ -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
 
index 72a6c131fc418937eaaa9a49d7d9b233871fe284..2e8b874deedb12408daa53372b2f1ce45752027a 100644 (file)
@@ -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();