Kaydet (Commit) a548924a authored tarafından Thomas Arnhold's avatar Thomas Arnhold

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
üst e75fba46
...@@ -29,19 +29,18 @@ class TOOLS_DLLPUBLIC TempFile ...@@ -29,19 +29,18 @@ class TOOLS_DLLPUBLIC TempFile
sal_Bool bKillingFileEnabled; sal_Bool bKillingFileEnabled;
public: public:
/** Create a temporary file or directory in a given folder or the default /** Create a temporary file in the default tempfile folder. */
tempfile folder. */ TempFile();
TempFile( const String* pParent=NULL, sal_Bool bDirectory=sal_False );
/** Create a temporary file or directory in a given folder or the default /** Create a temporary file in the default tempfile folder; its name starts
tempfile folder; its name starts with some given characters followed by with some given characters followed by a counter ( example:
a counter ( example: rLeadingChars="abc" means "abc0","abc1" and so on, rLeadingChars="abc" means "abc0", "abc1" and so on, depending on
depending on existing files in that folder ). existing files in that folder ).
The extension string may be f.e. ".txt" or "", if no extension string is The extension string may be f.e. ".txt" or "", if no extension string is
given, ".tmp" is used. 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 /** TempFile will be removed from disk in dtor if EnableKillingTempFile was
called before. TempDirs will be removed recursively in that case. */ called before. TempDirs will be removed recursively in that case. */
...@@ -59,7 +58,7 @@ public: ...@@ -59,7 +58,7 @@ public:
sal_Bool IsKillingFileEnabled() const { return bKillingFileEnabled; } sal_Bool IsKillingFileEnabled() const { return bKillingFileEnabled; }
/** Only create a name for a temporary file that would be valid at that moment. */ /** 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 #endif
......
...@@ -40,7 +40,6 @@ namespace { struct TempNameBase_Impl : public rtl::Static< ::rtl::OUString, Temp ...@@ -40,7 +40,6 @@ namespace { struct TempNameBase_Impl : public rtl::Static< ::rtl::OUString, Temp
struct TempFile_Impl struct TempFile_Impl
{ {
String aName; String aName;
sal_Bool bIsDirectory;
}; };
extern rtl::OUString GetSystemTempDirPath_Impl(); extern rtl::OUString GetSystemTempDirPath_Impl();
...@@ -55,33 +54,13 @@ rtl::OUString GetSystemTempDirPath_Impl() ...@@ -55,33 +54,13 @@ rtl::OUString GetSystemTempDirPath_Impl()
#define TMPNAME_SIZE ( 1 + 5 + 5 + 4 + 1 ) #define TMPNAME_SIZE ( 1 + 5 + 5 + 4 + 1 )
OUString ConstructTempDir_Impl( const String* pParent ) OUString ConstructTempDir_Impl()
{ {
OUString aName; // use system directory
if ( pParent && pParent->Len() ) ::rtl::OUString& rTempNameBase_Impl = TempNameBase_Impl::get();
{ if ( rTempNameBase_Impl.isEmpty() )
rtl::OUString aRet; rTempNameBase_Impl = GetSystemTempDirPath_Impl();
OUString aName = rTempNameBase_Impl;
// 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;
}
// Make sure that directory ends with a separator // Make sure that directory ends with a separator
if( !aName.endsWith( "/" ) ) if( !aName.endsWith( "/" ) )
...@@ -145,10 +124,10 @@ void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_Tru ...@@ -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 // get correct directory
String aName = ConstructTempDir_Impl( pParent ); String aName = ConstructTempDir_Impl();
// get TempFile name with default naming scheme // get TempFile name with default naming scheme
CreateTempName_Impl( aName, sal_False ); CreateTempName_Impl( aName, sal_False );
...@@ -156,28 +135,23 @@ String TempFile::CreateTempName( const String* pParent ) ...@@ -156,28 +135,23 @@ String TempFile::CreateTempName( const String* pParent )
return aName; return aName;
} }
TempFile::TempFile( const String* pParent, sal_Bool bDirectory ) TempFile::TempFile()
: pImp( new TempFile_Impl ) : pImp( new TempFile_Impl )
, bKillingFileEnabled( sal_False ) , bKillingFileEnabled( sal_False )
{ {
pImp->bIsDirectory = bDirectory;
// get correct directory // get correct directory
pImp->aName = ConstructTempDir_Impl( pParent ); pImp->aName = ConstructTempDir_Impl();
// get TempFile with default naming scheme // 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, TempFile::TempFile( const String& rLeadingChars, const String* pExtension )
const String* pParent, sal_Bool bDirectory )
: pImp( new TempFile_Impl ) : pImp( new TempFile_Impl )
, bKillingFileEnabled( sal_False ) , bKillingFileEnabled( sal_False )
{ {
pImp->bIsDirectory = bDirectory;
// get correct directory // 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 // now use special naming scheme ( name takes leading chars and an index counting up from zero
aName += rLeadingChars; aName += rLeadingChars;
...@@ -191,32 +165,17 @@ TempFile::TempFile( const String& rLeadingChars, const String* pExtension, ...@@ -191,32 +165,17 @@ TempFile::TempFile( const String& rLeadingChars, const String* pExtension,
aTmpBuffer.append(".tmp"); aTmpBuffer.append(".tmp");
rtl::OUString aTmp = aTmpBuffer.makeStringAndClear(); 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 ); pImp->aName = aTmp;
if ( err == FileBase::E_None ) aFile.close();
{ break;
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;
} }
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() ...@@ -224,15 +183,7 @@ TempFile::~TempFile()
{ {
if ( bKillingFileEnabled ) if ( bKillingFileEnabled )
{ {
if ( pImp->bIsDirectory ) File::remove( pImp->aName );
{
// at the moment no recursiv algorithm present
Directory::remove( pImp->aName );
}
else
{
File::remove( pImp->aName );
}
} }
delete pImp; delete pImp;
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include <com/sun/star/ucb/UniversalContentBroker.hpp> #include <com/sun/star/ucb/UniversalContentBroker.hpp>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <unotools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include <tools/tempfile.hxx>
#include <unotools/localfilehelper.hxx> #include <unotools/localfilehelper.hxx>
#include <unotools/ucbstreamhelper.hxx> #include <unotools/ucbstreamhelper.hxx>
#include <ucbhelper/fileidentifierconverter.hxx> #include <ucbhelper/fileidentifierconverter.hxx>
......
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