[Libreoffice-commits] core.git: include/osl sal/osl sal/util unotools/source

Stephan Bergmann sbergman at redhat.com
Tue May 20 09:14:10 PDT 2014


 include/osl/file.h                     |   16 ++++++++++++++++
 include/osl/file.hxx                   |   11 +++++++++--
 sal/osl/unx/file_misc.cxx              |   26 ++++++++++++++++++++++----
 sal/osl/w32/file_dirvol.cxx            |    6 ++++++
 sal/util/sal.map                       |    1 +
 unotools/source/ucbhelper/tempfile.cxx |    5 ++++-
 6 files changed, 58 insertions(+), 7 deletions(-)

New commits:
commit f65de4feee506b80be0986ce28f7a2311e4fbe2c
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue May 20 18:07:54 2014 +0200

    fdo#60338: Introduce osl_createDirectoryWithFlags
    
    ...so that utl::TempFile can pass osl_File_OpenFlag_Private and doesn't have to
    resort to umask (the calls to umask around Directory::create had somewhat
    erroneously been removed recently with 1d72a0262c4570631d0aa8f98e34e21fb9d6ae42
    "Related fdo#60338: Create missing temp file dir with user's original umask,"
    mistaking this for creation of intermediate directories in the hierarchy).
    
    On Windows, the flags argument to osl_createDirectoryWithFlags is ignored
    completely for now.
    
    Change-Id: Iac56a5049d579be729a3f338aa62105123edb6cb

diff --git a/include/osl/file.h b/include/osl/file.h
index c00a302..1f1ae1b 100644
--- a/include/osl/file.h
+++ b/include/osl/file.h
@@ -1130,6 +1130,22 @@ SAL_DLLPUBLIC oslFileError SAL_CALL osl_closeFile( oslFileHandle Handle );
 
 SAL_DLLPUBLIC oslFileError SAL_CALL osl_createDirectory( rtl_uString* pustrDirectoryURL );
 
+/** Create a directory, passing flags.
+
+    @param url
+    File URL of the directory to create.
+
+    @param flags
+    A combination of the same osl_File_OpenFlag_*s used by osl_openFile,
+    except that osl_File_OpenFlag_Create is implied and ignored.  Support for
+    the various flags can differ across operating systems.
+
+    @see osl_createDirectory()
+
+    @since LibreOffice 4.3
+*/
+SAL_DLLPUBLIC oslFileError SAL_CALL osl_createDirectoryWithFlags(
+    rtl_uString * url, sal_uInt32 flags);
 
 /** Remove an empty directory.
 
diff --git a/include/osl/file.hxx b/include/osl/file.hxx
index 1e600e7..8f7f3b4 100644
--- a/include/osl/file.hxx
+++ b/include/osl/file.hxx
@@ -1849,6 +1849,10 @@ public:
         @param ustrDirectoryURL [in]
         Full qualified URL of the directory to create.
 
+        @param flags [in]
+        Optional flags, see osl_createDirectoryWithFlags for details.  This
+        defaulted parameter is new since LibreOffice 4.3.
+
         @return
         E_None on success
         E_INVAL the format of the parameters was not valid
@@ -1871,9 +1875,12 @@ public:
         @see remove()
     */
 
-    inline static RC create( const ::rtl::OUString& ustrDirectoryURL )
+    inline static RC create(
+        const ::rtl::OUString& ustrDirectoryURL,
+        sal_Int32 flags = osl_File_OpenFlag_Read | osl_File_OpenFlag_Write )
     {
-        return static_cast< RC >( osl_createDirectory( ustrDirectoryURL.pData ) );
+        return static_cast< RC >(
+            osl_createDirectoryWithFlags( ustrDirectoryURL.pData, flags ) );
     }
 
     /** Remove an empty directory.
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx
index 787866e..eb1e151 100644
--- a/sal/osl/unx/file_misc.cxx
+++ b/sal/osl/unx/file_misc.cxx
@@ -131,7 +131,8 @@ oslFileType DirectoryItem_Impl::getFileType() const
     return osl_File_Type_Unknown;
 }
 
-static oslFileError osl_psz_createDirectory(const sal_Char* pszPath);
+static oslFileError osl_psz_createDirectory(
+    char const * pszPath, sal_uInt32 flags);
 static oslFileError osl_psz_removeDirectory(const sal_Char* pszPath);
 
 oslFileError SAL_CALL osl_openDirectory(rtl_uString* ustrDirectoryURL, oslDirectory* pDirectory)
@@ -395,6 +396,13 @@ oslFileError SAL_CALL osl_releaseDirectoryItem( oslDirectoryItem Item )
 
 oslFileError SAL_CALL osl_createDirectory( rtl_uString* ustrDirectoryURL )
 {
+    return osl_createDirectoryWithFlags(
+        ustrDirectoryURL, osl_File_OpenFlag_Read | osl_File_OpenFlag_Write);
+}
+
+oslFileError osl_createDirectoryWithFlags(
+    rtl_uString * ustrDirectoryURL, sal_uInt32 flags)
+{
     char path[PATH_MAX];
     oslFileError eRet;
 
@@ -410,7 +418,7 @@ oslFileError SAL_CALL osl_createDirectory( rtl_uString* ustrDirectoryURL )
       return oslTranslateFileError( OSL_FET_ERROR, errno );
 #endif/* MACOSX */
 
-    return osl_psz_createDirectory( path );
+    return osl_psz_createDirectory( path, flags );
 }
 
 oslFileError SAL_CALL osl_removeDirectory( rtl_uString* ustrDirectoryURL )
@@ -433,10 +441,20 @@ oslFileError SAL_CALL osl_removeDirectory( rtl_uString* ustrDirectoryURL )
     return osl_psz_removeDirectory( path );
 }
 
-static oslFileError osl_psz_createDirectory( const sal_Char* pszPath )
+oslFileError osl_psz_createDirectory(char const * pszPath, sal_uInt32 flags)
 {
     int nRet=0;
-    int mode = S_IRWXU | S_IRWXG | S_IRWXO;
+    int mode
+        = (((flags & osl_File_OpenFlag_Read) == 0
+            ? 0
+            : ((flags & osl_File_OpenFlag_Private) == 0
+               ? S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH
+               : S_IRUSR | S_IXUSR))
+           | ((flags & osl_File_OpenFlag_Write) == 0
+              ? 0
+              : ((flags & osl_File_OpenFlag_Private) == 0
+                 ? S_IWUSR | S_IWGRP | S_IWOTH
+                 : S_IWUSR)));
 
     nRet = mkdir(pszPath,mode);
 
diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx
index 2d2c9f6..51bef22 100644
--- a/sal/osl/w32/file_dirvol.cxx
+++ b/sal/osl/w32/file_dirvol.cxx
@@ -691,6 +691,12 @@ oslFileError SAL_CALL osl_createDirectoryPath(
 
 oslFileError SAL_CALL osl_createDirectory(rtl_uString* strPath)
 {
+    return osl_createDirectoryWithFlags(
+        strPath, osl_File_OpenFlag_Read | osl_File_OpenFlag_Write);
+}
+
+oslFileError osl_createDirectoryWithFlags(rtl_uString * strPath, sal_uInt32)
+{
     rtl_uString *strSysPath = NULL;
     oslFileError    error = _osl_getSystemPathFromFileURL( strPath, &strSysPath, sal_False );
 
diff --git a/sal/util/sal.map b/sal/util/sal.map
index e601c6d..1d7d491 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -672,6 +672,7 @@ LIBO_UDK_4.2 { # symbols available in >= LibO 4.2
 
 LIBO_UDK_4.3 { # symbols available in >= LibO 4.3
     global:
+        osl_createDirectoryWithFlags;
         rtl_allocateAlignedMemory;
         rtl_freeAlignedMemory;
 } LIBO_UDK_4.2;
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index 5b9cae7..9b8d3b5 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -242,7 +242,10 @@ OUString lcl_createName(
             aTmp += ".tmp";
         if ( bDirectory )
         {
-            FileBase::RC err = Directory::create( aTmp );
+            FileBase::RC err = Directory::create(
+                aTmp,
+                (osl_File_OpenFlag_Read | osl_File_OpenFlag_Write
+                 | osl_File_OpenFlag_Private));
             if ( err == FileBase::E_None )
             {
                 // !bKeep: only for creating a name, not a file or directory


More information about the Libreoffice-commits mailing list