summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Arnhold <thomas@arnhold.org>2013-03-06 02:24:16 +0100
committerThomas Arnhold <thomas@arnhold.org>2013-03-12 16:20:15 +0100
commita548924aece3dc99b2aa36b5c9b0fa52de9951ae (patch)
treeffdef75d5a8a3353cbbff675b0f9e710ab3abbcf
parente75fba46b0080df4fb415bdefacf74a167b6cb6e (diff)
tempfile: Creating tempfiles in a given folder is not used
It's always the case, that the default temp folder is used. aName and aRet are always empty, pParent is no longer used. So the pParent argument makes no sense anymore. bDirectory makes no sense without pParent and is apparently unused (always sal_False by default). The include of tools/tempfile.hxx in unotools/tempfile.cxx in not necessary. Conflicts: tools/source/fsys/tempfile.cxx Change-Id: I9c53b263a640e53140a8ae8795181b1c5e43f26d
-rw-r--r--tools/inc/tools/tempfile.hxx17
-rw-r--r--tools/source/fsys/tempfile.cxx95
-rw-r--r--unotools/source/ucbhelper/tempfile.cxx1
3 files changed, 31 insertions, 82 deletions
diff --git a/tools/inc/tools/tempfile.hxx b/tools/inc/tools/tempfile.hxx
index 9e84adc96a51..8ef8c574cf7c 100644
--- a/tools/inc/tools/tempfile.hxx
+++ b/tools/inc/tools/tempfile.hxx
@@ -29,19 +29,18 @@ class TOOLS_DLLPUBLIC TempFile
sal_Bool bKillingFileEnabled;
public:
- /** Create a temporary file or directory in a given folder or the default
- tempfile folder. */
- TempFile( const String* pParent=NULL, sal_Bool bDirectory=sal_False );
+ /** Create a temporary file in the default tempfile folder. */
+ TempFile();
- /** Create a temporary file or directory in a given folder or the default
- tempfile folder; its name starts with some given characters followed by
- a counter ( example: rLeadingChars="abc" means "abc0","abc1" and so on,
- depending on existing files in that folder ).
+ /** Create a temporary file in the default tempfile folder; its name starts
+ with some given characters followed by a counter ( example:
+ rLeadingChars="abc" means "abc0", "abc1" and so on, depending on
+ existing files in that folder ).
The extension string may be f.e. ".txt" or "", if no extension string is
given, ".tmp" is used.
*/
- TempFile( const String& rLeadingChars, const String* pExtension=NULL, const String* pParent=NULL, sal_Bool bDirectory=sal_False );
+ TempFile( const String& rLeadingChars, const String* pExtension=NULL );
/** TempFile will be removed from disk in dtor if EnableKillingTempFile was
called before. TempDirs will be removed recursively in that case. */
@@ -59,7 +58,7 @@ public:
sal_Bool IsKillingFileEnabled() const { return bKillingFileEnabled; }
/** Only create a name for a temporary file that would be valid at that moment. */
- static String CreateTempName( const String* pParent=NULL );
+ static String CreateTempName();
};
#endif
diff --git a/tools/source/fsys/tempfile.cxx b/tools/source/fsys/tempfile.cxx
index ab80c70c0dfe..9308d7a26846 100644
--- a/tools/source/fsys/tempfile.cxx
+++ b/tools/source/fsys/tempfile.cxx
@@ -40,7 +40,6 @@ namespace { struct TempNameBase_Impl : public rtl::Static< ::rtl::OUString, Temp
struct TempFile_Impl
{
String aName;
- sal_Bool bIsDirectory;
};
extern rtl::OUString GetSystemTempDirPath_Impl();
@@ -55,33 +54,13 @@ rtl::OUString GetSystemTempDirPath_Impl()
#define TMPNAME_SIZE ( 1 + 5 + 5 + 4 + 1 )
-OUString ConstructTempDir_Impl( const String* pParent )
+OUString ConstructTempDir_Impl()
{
- OUString aName;
- if ( pParent && pParent->Len() )
- {
- rtl::OUString aRet;
-
- // test for valid filename
- {
- ::osl::DirectoryItem aItem;
- sal_Int32 i = aRet.getLength();
- if ( aRet[i-1] == '/' )
- i--;
-
- if ( DirectoryItem::get( aRet.copy(0, i), aItem ) == FileBase::E_None )
- aName = aRet;
- }
- }
-
- if ( aName.isEmpty() )
- {
- // if no parent or invalid parent : use system directory
- ::rtl::OUString& rTempNameBase_Impl = TempNameBase_Impl::get();
- if ( rTempNameBase_Impl.isEmpty() )
- osl::FileBase::getTempDirURL( rTempNameBase_Impl );
- aName = rTempNameBase_Impl;
- }
+ // use system directory
+ ::rtl::OUString& rTempNameBase_Impl = TempNameBase_Impl::get();
+ if ( rTempNameBase_Impl.isEmpty() )
+ rTempNameBase_Impl = GetSystemTempDirPath_Impl();
+ OUString aName = rTempNameBase_Impl;
// Make sure that directory ends with a separator
if( !aName.endsWith( "/" ) )
@@ -145,10 +124,10 @@ void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_Tru
}
}
-String TempFile::CreateTempName( const String* pParent )
+String TempFile::CreateTempName()
{
// get correct directory
- String aName = ConstructTempDir_Impl( pParent );
+ String aName = ConstructTempDir_Impl();
// get TempFile name with default naming scheme
CreateTempName_Impl( aName, sal_False );
@@ -156,28 +135,23 @@ String TempFile::CreateTempName( const String* pParent )
return aName;
}
-TempFile::TempFile( const String* pParent, sal_Bool bDirectory )
+TempFile::TempFile()
: pImp( new TempFile_Impl )
, bKillingFileEnabled( sal_False )
{
- pImp->bIsDirectory = bDirectory;
-
// get correct directory
- pImp->aName = ConstructTempDir_Impl( pParent );
+ pImp->aName = ConstructTempDir_Impl();
// get TempFile with default naming scheme
- CreateTempName_Impl( pImp->aName, sal_True, bDirectory );
+ CreateTempName_Impl( pImp->aName, sal_True );
}
-TempFile::TempFile( const String& rLeadingChars, const String* pExtension,
- const String* pParent, sal_Bool bDirectory )
+TempFile::TempFile( const String& rLeadingChars, const String* pExtension )
: pImp( new TempFile_Impl )
, bKillingFileEnabled( sal_False )
{
- pImp->bIsDirectory = bDirectory;
-
// get correct directory
- String aName = ConstructTempDir_Impl( pParent );
+ String aName = ConstructTempDir_Impl();
// now use special naming scheme ( name takes leading chars and an index counting up from zero
aName += rLeadingChars;
@@ -191,32 +165,17 @@ TempFile::TempFile( const String& rLeadingChars, const String* pExtension,
aTmpBuffer.append(".tmp");
rtl::OUString aTmp = aTmpBuffer.makeStringAndClear();
- if ( bDirectory )
+ File aFile( aTmp );
+ FileBase::RC err = aFile.open(osl_File_OpenFlag_Create);
+ if ( err == FileBase::E_None )
{
- FileBase::RC err = Directory::create( aTmp );
- if ( err == FileBase::E_None )
- {
- pImp->aName = aTmp;
- break;
- }
- else if ( err != FileBase::E_EXIST )
- // if f.e. name contains invalid chars stop trying to create dirs
- break;
- }
- else
- {
- File aFile( aTmp );
- FileBase::RC err = aFile.open(osl_File_OpenFlag_Create);
- if ( err == FileBase::E_None )
- {
- pImp->aName = aTmp;
- aFile.close();
- break;
- }
- else if ( err != FileBase::E_EXIST )
- // if f.e. name contains invalid chars stop trying to create dirs
- break;
+ pImp->aName = aTmp;
+ aFile.close();
+ break;
}
+ else if ( err != FileBase::E_EXIST )
+ // if f.e. name contains invalid chars stop trying to create dirs
+ break;
}
}
@@ -224,15 +183,7 @@ TempFile::~TempFile()
{
if ( bKillingFileEnabled )
{
- if ( pImp->bIsDirectory )
- {
- // at the moment no recursiv algorithm present
- Directory::remove( pImp->aName );
- }
- else
- {
- File::remove( pImp->aName );
- }
+ File::remove( pImp->aName );
}
delete pImp;
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index 5ffb316b0b78..807c776826cb 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -22,7 +22,6 @@
#include <com/sun/star/ucb/UniversalContentBroker.hpp>
#include <comphelper/processfactory.hxx>
#include <unotools/tempfile.hxx>
-#include <tools/tempfile.hxx>
#include <unotools/localfilehelper.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <ucbhelper/fileidentifierconverter.hxx>