Kaydet (Commit) a82f7b20 authored tarafından Michael Meeks's avatar Michael Meeks

port horrible tools temp directory abstraction to sal.

Change-Id: I3688c8babf7719091404317b13014283a8ce9492
üst c607d643
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
using namespace osl; using namespace osl;
using ::rtl::OUString; using ::rtl::OUString;
int ApiRet2ToSolarError_Impl( int nApiRet ); extern rtl::OUString GetSystemTempDirPath_Impl();
int Sys2SolarError_Impl( int nSysErr ) int Sys2SolarError_Impl( int nSysErr )
{ {
...@@ -1304,9 +1304,13 @@ DirEntry DirEntry::TempName( DirEntryKind eKind ) const ...@@ -1304,9 +1304,13 @@ DirEntry DirEntry::TempName( DirEntryKind eKind ) const
} }
dir = aDirName.getStr(); dir = aDirName.getStr();
char sBuf[_MAX_PATH]; OString sTempRoot;
if ( eFlag == FSYS_FLAG_CURRENT || ( !pParent && pWild ) ) if ( eFlag == FSYS_FLAG_CURRENT || ( !pParent && pWild ) )
dir = TempDirImpl(sBuf); {
rtl::OUString aPath = GetSystemTempDirPath_Impl();
sTempRoot = OUStringToOString( aPath, osl_getThreadTextEncoding() );
dir = sTempRoot.getStr();
}
DirEntry aRet(FSYS_FLAG_INVALID); DirEntry aRet(FSYS_FLAG_INVALID);
i = strlen(dir); i = strlen(dir);
......
...@@ -43,26 +43,21 @@ struct TempFile_Impl ...@@ -43,26 +43,21 @@ struct TempFile_Impl
sal_Bool bIsDirectory; sal_Bool bIsDirectory;
}; };
String GetSystemTempDir_Impl() extern rtl::OUString GetSystemTempDirPath_Impl();
rtl::OUString GetSystemTempDirPath_Impl()
{ {
char sBuf[_MAX_PATH]; rtl::OUString aTmpURL, aPath;
const char *pDir = TempDirImpl(sBuf); osl::FileBase::getTempDirURL( aTmpURL );
osl::FileBase::getSystemPathFromFileURL( aTmpURL, aPath );
::rtl::OString aTmpA( pDir ); return aPath;
::rtl::OUString aTmp = ::rtl::OStringToOUString( aTmpA, osl_getThreadTextEncoding() );
rtl::OUString aRet;
FileBase::getFileURLFromSystemPath( aTmp, aRet );
String aName = aRet;
if( aName.GetChar(aName.Len()-1) != '/' )
aName += '/';
return aName;
} }
#define TMPNAME_SIZE ( 1 + 5 + 5 + 4 + 1 ) #define TMPNAME_SIZE ( 1 + 5 + 5 + 4 + 1 )
String ConstructTempDir_Impl( const String* pParent ) OUString ConstructTempDir_Impl( const String* pParent )
{ {
String aName; OUString aName;
if ( pParent && pParent->Len() ) if ( pParent && pParent->Len() )
{ {
rtl::OUString aRet; rtl::OUString aRet;
...@@ -79,19 +74,18 @@ String ConstructTempDir_Impl( const String* pParent ) ...@@ -79,19 +74,18 @@ String ConstructTempDir_Impl( const String* pParent )
} }
} }
if ( !aName.Len() ) if ( aName.isEmpty() )
{ {
// if no parent or invalid parent : use system directory // if no parent or invalid parent : use system directory
::rtl::OUString& rTempNameBase_Impl = TempNameBase_Impl::get(); ::rtl::OUString& rTempNameBase_Impl = TempNameBase_Impl::get();
if ( rTempNameBase_Impl.isEmpty() ) if ( rTempNameBase_Impl.isEmpty() )
rTempNameBase_Impl = GetSystemTempDir_Impl(); rTempNameBase_Impl = GetSystemTempDirPath_Impl();
aName = rTempNameBase_Impl; aName = rTempNameBase_Impl;
} }
// Make sure that directory ends with a separator // Make sure that directory ends with a separator
xub_StrLen i = aName.Len(); if( !aName.endsWith( "/" ) )
if( i>0 && aName.GetChar(i-1) != '/' ) aName += "/";
aName += '/';
return aName; return aName;
} }
......
...@@ -363,26 +363,4 @@ sal_Bool FileStat::Update( const DirEntry& rDirEntry, SAL_UNUSED_PARAMETER sal_B ...@@ -363,26 +363,4 @@ sal_Bool FileStat::Update( const DirEntry& rDirEntry, SAL_UNUSED_PARAMETER sal_B
return sal_True; return sal_True;
} }
const char *TempDirImpl( char *pBuf )
{
#ifdef MACOSX
// P_tmpdir is /var/tmp on Mac OS X, and it is not cleaned up on system
// startup
strcpy( pBuf, "/tmp" );
#else
const char *pValue = getenv( "TEMP" );
if ( !pValue )
pValue = getenv( "TMP" );
if ( pValue )
strcpy( pBuf, pValue );
else
// P_tempdir exists in Solaris and Linux
strcpy( pBuf, P_tmpdir );
// don't use "/tmp" as hard coded directory
//strcpy( pBuf, "/tmp" );
#endif /* MACOSX */
return pBuf;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -71,8 +71,6 @@ inline void Unx2DateAndTime( time_t nDate, Time& rTime, Date& rDate ) ...@@ -71,8 +71,6 @@ inline void Unx2DateAndTime( time_t nDate, Time& rTime, Date& rDate )
rDate = Date( pTime->tm_mday, pTime->tm_mon + 1, pTime->tm_year + 1900 ); rDate = Date( pTime->tm_mday, pTime->tm_mon + 1, pTime->tm_year + 1900 );
} }
const char* TempDirImpl( char *pBuf );
#define FSysFailOnErrorImpl() #define FSysFailOnErrorImpl()
#endif #endif
......
...@@ -776,15 +776,4 @@ sal_Bool IsRedirectable_Impl( const rtl::OString& rPath ) ...@@ -776,15 +776,4 @@ sal_Bool IsRedirectable_Impl( const rtl::OString& rPath )
return sal_False; return sal_False;
} }
/// get name of the directory for temporary files
const char* TempDirImpl( char *pBuf )
{
if ( !GetTempPath( MAX_PATH, pBuf ) &&
!GetWindowsDirectory( pBuf, MAX_PATH ) &&
!GetEnvironmentVariable( "HOMEPATH", pBuf, MAX_PATH ) )
return 0;
return pBuf;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -63,8 +63,6 @@ inline sal_Bool DRIVE_EXISTS(char c) ...@@ -63,8 +63,6 @@ inline sal_Bool DRIVE_EXISTS(char c)
return GetDriveType( aDriveRoot.getStr() ) > 1; return GetDriveType( aDriveRoot.getStr() ) > 1;
} }
const char* TempDirImpl( char *pBuf );
#define FSysFailOnErrorImpl() #define FSysFailOnErrorImpl()
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment