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
This commit is contained in:
parent
1122d513ef
commit
f65de4feee
@ -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.
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
@ -394,6 +395,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);
|
||||
|
||||
|
@ -690,6 +690,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 );
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user