• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
KTempDir Class Reference

#include <KTempDir>

Public Member Functions

 KTempDir (const QString &directoryPrefix=QString(), int mode=0700)
 
 ~KTempDir ()
 
bool autoRemove () const
 
bool exists () const
 
QString name () const
 
void setAutoRemove (bool autoRemove)
 
int status () const
 
void unlink ()
 

Static Public Member Functions

static bool removeDir (const QString &path)
 

Protected Member Functions

bool create (const QString &directoryPrefix, int mode)
 

Detailed Description

Create a unique directory for temporary use.

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(KStandardDirs::locateLocal("tmp", prefix));

KTempDir does not create any missing directories, but KStandardDirs::locateLocal() does.

See also
KStandardDirs
KTemporaryFile
Author
Joseph Wenninger jowen.nosp@m.n@kd.nosp@m.e.org

Definition at line 52 of file ktempdir.h.

Constructor & Destructor Documentation

KTempDir::KTempDir ( const QString &  directoryPrefix = QString(),
int  mode = 0700 
)
explicit

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

The default directoryPrefix is "$KDEHOME/tmp-$HOST/appname", i.e. as returned by KStandardDirs::locateLocal("tmp", KGlobal::mainComponent().componentName())

Parameters
directoryPrefixthe prefix of the file name, or QString() 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 third for other users not in the file's group, with the same values.

Definition at line 80 of file ktempdir.cpp.

KTempDir::~KTempDir ( )

The destructor deletes the directory and its contents if autoRemove is set to true.

See also
setAutoRemove.

Definition at line 154 of file ktempdir.cpp.

Member Function Documentation

bool KTempDir::autoRemove ( ) const
Returns
whether auto remove is active
See also
setAutoRemove

Definition at line 183 of file ktempdir.cpp.

bool KTempDir::create ( const QString &  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
true upon success

Definition at line 85 of file ktempdir.cpp.

bool KTempDir::exists ( ) const

Returns true if a temporary directory has successfully been created and has not been unlinked yet.

Definition at line 173 of file ktempdir.cpp.

QString KTempDir::name ( ) const

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

Returns
The name of the directory, or QString() if creating the directory has failed or the directory has been unlinked

Definition at line 168 of file ktempdir.cpp.

bool KTempDir::removeDir ( const QString &  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::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.)
Todo:
decide how and where this function should be defined in KDE5

Definition at line 259 of file ktempdir.cpp.

void KTempDir::setAutoRemove ( bool  autoRemove)

Turn automatic deletion of the directory on or off.

Automatic deletion is on by default.

Parameters
autoRemovetoggle automatic deletion on or off

Definition at line 178 of file ktempdir.cpp.

int KTempDir::status ( ) const

Returns the status of the directory creation based on errno.

(see errno.h)

Note
You should check the status after object creation to check whether the directory could be created.
Returns
the errno status, 0 means ok

Definition at line 163 of file ktempdir.cpp.

void KTempDir::unlink ( )

Deletes the directory recursively.

Definition at line 188 of file ktempdir.cpp.


The documentation for this class was generated from the following files:
  • ktempdir.h
  • ktempdir.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:13 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal