25 #include <sys/types.h>
27 #ifdef HAVE_SYS_STAT_H
44 #define _PATH_TMP "/tmp"
47 #include <tqdatetime.h>
50 #include "tdeglobal.h"
51 #include "tdeapplication.h"
52 #include "kinstance.h"
54 #include "kstandarddirs.h"
64 if (directoryPrefix.isEmpty())
68 (void)
create(directoryPrefix , mode);
77 TQCString nme = TQFile::encodeName(directoryPrefix) +
"XXXXXX";
79 if((realName=mkdtemp(nme.data())) == 0)
82 TQCString nme = TQFile::encodeName(directoryPrefix) +
"XXXXXX";
83 tqWarning(
"KTempDir: Error trying to create %s: %s", nme.data(), strerror(errno));
85 mTmpName = TQString::null;
90 TQCString realNameStr(realName);
91 mTmpName = TQFile::decodeName(realNameStr)+
"/";
92 kdDebug(180) <<
"KTempDir: Temporary directory created :" << mTmpName <<
endl;
94 mode_t umsk = umask(tmp);
96 chmod(nme, mode&(~umsk));
102 chown(nme, getuid(), getgid());
136 if (bExisting)
return new TQDir(mTmpName);
143 if (!bExisting)
return;
153 rmtree(
const TQCString& name)
155 kdDebug() <<
"Checking directory for remove " << name <<
endl;
157 if ( KDE_lstat( name.data(), &st ) == -1 )
159 if ( S_ISDIR( st.st_mode ) )
162 kdDebug() <<
"File " << name <<
" is DIRECTORY!" <<
endl;
163 KDE_struct_dirent* ep;
164 DIR* dp = ::opendir( name.data() );
167 while ( ( ep = KDE_readdir( dp ) ) )
169 kdDebug() <<
"CHECKING " << name <<
"/" << ep->d_name <<
endl;
170 if ( !qstrcmp( ep->d_name,
"." ) || !qstrcmp( ep->d_name,
".." ) )
172 TQCString newName( name );
174 newName += ep->d_name;
183 if ( ::closedir( dp ) )
187 if ( ! rmtree( newName ) )
190 dp = ::opendir( name.data() );
194 if ( ::closedir( dp ) )
197 return ! ::rmdir( name );
203 return ! ::unlink( name );
210 kdDebug() << k_funcinfo <<
" " << path <<
endl;
211 if ( !TQFile::exists( path ) )
214 const TQCString cstr( TQFile::encodeName( path ) );
215 return rmtree( cstr );
void unlink()
Deletes the directory recursively.
KTempDir(TQString directoryPrefix=TQString::null, int mode=0700)
Creates a temporary directory with the name: <directoryPrefix><six letters>
TQString name() const
Returns the full path and name of the directory, including a trailing '/'.
bool create(const TQString &directoryPrefix, int mode)
Creates a "random" directory with specified mode.
TQDir * qDir()
Returns the TQDir* of the temporary directory.
int status() const
Returns the status of the directory creation based on errno.
~KTempDir()
The destructor deletes the directory and it's contents if autoDelete is enabled.
static bool removeDir(const TQString &path)
Remove a directory and all its contents.
static int random()
Generates a uniform random number.
static TDEInstance * instance()
Returns the global instance.
kndbgstream & endl(kndbgstream &s)
Does nothing.
kdbgstream kdDebug(int area=0)
Returns a debug stream.
kdbgstream & endl(kdbgstream &s)
Prints an "\n".
const char * name(StdAction id)