• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdecore
 

kdecore

Public Member Functions | Static Public Member Functions | Protected Member Functions
KTempDir Class Reference

#include <ktempdir.h>

List of all members.

Public Member Functions

 KTempDir (TQString directoryPrefix=TQString::null, int mode=0700)
 ~KTempDir ()
void setAutoDelete (bool autoDelete)
int status () const
TQString name () const
TQDir * qDir ()
void unlink ()
bool existing () const

Static Public Member Functions

static bool removeDir (const TQString &path)

Protected Member Functions

bool create (const TQString &directoryPrefix, int mode)
void setError (int error)

Detailed Description

The KTempDir class creates a unique directory for temporary use.

This is especially useful if you need to create a directory in a world writable directory like /tmp without being vulnerable to so called symlink attacks.

KDE applications, however, shouldn't create files or directories in /tmp in the first place but use the "tmp" resource instead. The standard KTempDir constructor will do that by default.

To create a temporary directory that starts with a certain name in the "tmp" resource, one should use: KTempDir(locateLocal("tmp", prefix));

KTempFile does not create any missing directories, but locateLocal() does.

See also KStandardDirs

Since:
3.2
Author:
Joseph Wenninger <jowenn@kde.org>

Definition at line 53 of file ktempdir.h.


Constructor & Destructor Documentation

KTempDir::KTempDir ( TQString  directoryPrefix = TQString::null,
int  mode = 0700 
)

Creates a temporary directory with the name: <directoryPrefix><six letters>

The default directoryPrefix is "$KDEHOME/tmp-$HOST/appname"

Parameters:
directoryPrefixthe prefix of the file name, or TQString::null for the default value
modethe file permissions, almost always in octal. The first digit selects permissions for the user who owns the file: read (4), write (2), and execute (1); the second selects permissions for other users in the file's group, with the same values; and the fourth for other users not in the file's group, with the same values.

Definition at line 59 of file ktempdir.cpp.

KTempDir::~KTempDir ( )

The destructor deletes the directory and it's contents if autoDelete is enabled.

Definition at line 106 of file ktempdir.cpp.


Member Function Documentation

bool KTempDir::create ( const TQString &  directoryPrefix,
int  mode 
) [protected]

Creates a "random" directory with specified mode.

Parameters:
directoryPrefixto use when creating temp directory (the rest is generated randomly)
modedirectory permissions
Returns:
bool true upon sucess

Definition at line 72 of file ktempdir.cpp.

bool KTempDir::existing ( ) const
Returns:
true if a temporary directory has successfully been created and not been unlinked yet

Definition at line 128 of file ktempdir.cpp.

TQString KTempDir::name ( ) const

Returns the full path and name of the directory, including a trailing '/'.

Returns:
The name of the directory, or TQString::null if creating the directory has failed or the directory has been unlinked

Definition at line 122 of file ktempdir.cpp.

TQDir * KTempDir::qDir ( )

Returns the TQDir* of the temporary directory.

Returns:
TQDir directory information of the directory or 0 if their is no managed directory The caller has to free the pointer open for writing to the

Definition at line 134 of file ktempdir.cpp.

bool KTempDir::removeDir ( const TQString &  path) [static]

Remove a directory and all its contents.

Remove recursively a directory, even if it is not empty or contains other directories.

However the function works too when the path given is a non-directory file. In that case it simply remove that file.

The function stops on the first error.

Note:
This function is more meant for removing a directory not created by the user. For user-created directories, using KIO::NetAccess::del is recommended instead, especially as it has user feedback for long operations.
Parameters:
pathPath of the directory to delete
Returns:
true if successful, otherwise false (Use errno for more details about the error.)
Since:
3.5.2

Definition at line 208 of file ktempdir.cpp.

void KTempDir::setAutoDelete ( bool  autoDelete) [inline]

Turn automatic deletion on or off.

Automatic deletion is off by default.

Parameters:
autoDeletetrue to turn automatic deletion on

Definition at line 85 of file ktempdir.h.

void KTempDir::setError ( int  error) [inline, protected]

Sets the errno value.

Parameters:
errorthe value to set the status to.

Definition at line 161 of file ktempdir.h.

int KTempDir::status ( ) const

Returns the status of the directory creation based on errno.

(see errno.h) 0 means OK.

You should check the status after object creation to check whether a directory could be created in the first place.

Returns:
the errno status, 0 means ok

Definition at line 116 of file ktempdir.cpp.

void KTempDir::unlink ( )

Deletes the directory recursively.

Definition at line 141 of file ktempdir.cpp.


The documentation for this class was generated from the following files:
  • ktempdir.h
  • ktempdir.cpp

kdecore

Skip menu "kdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdecore

Skip menu "kdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdecore by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |