ssu
Loading...
Searching...
No Matches
Sandbox Class Reference

Helps to redirect file operations into sandbox directory. More...

Public Types

enum  Usage { UseDirectly , UseAsSkeleton }
enum  Scope { ThisProcess = 0x01 , ChildProcesses = 0x02 }

Public Member Functions

 Sandbox (const QString &sandboxPath, Usage usage, Scopes scopes)
bool activate ()
void deactivate ()
bool isActive () const
bool addWorldFiles (const QString &directory, QDir::Filters filters=QDir::NoFilter, const QStringList &filterNames=QStringList(), bool recurse=true)
bool addWorldFile (const QString &file)

Static Public Member Functions

static QDir effectiveRootDir ()
static QString map (const QString &fileName)
static QString map (const QString &pathName, const QString &fileName)

Detailed Description

Helps to redirect file operations into sandbox directory.

The term world files is used to reffer files outside sandbox.

To write a sandbox aware code, simply use the map() function to process paths before accessing them.

QFile data(Sandbox::map("/usr/share/my_app/data"));
data.open();
...

Its effect is controlled by activate() and deactivate() calls. Only one Sandbox instance can be active at any time. Active sandbox is automatically deactivated upon destruction.

When constructed without arguments, path to sandbox directory is get from SSU_SANDBOX_DIR environment variable.

Attention
When constructed without arguments, it is activated automatically and failure to do so is reported with qFatal(), i.e., application will be abort()ed.

When constructed with usage UseAsSkeleton, it will first make temporary copy of sandboxPath to work on and files in the original directory will stay untouched. Also see addWorldFiles().

The argument @scopes allows to control if the sandbox will be used by this process, its children processes (SSU_SANDBOX_DIR environment variable will be exported), or both.

Definition at line 21 of file sandbox_p.h.

Member Enumeration Documentation

◆ Scope

enum Sandbox::Scope

Definition at line 29 of file sandbox_p.h.

◆ Usage

enum Sandbox::Usage

Definition at line 24 of file sandbox_p.h.

Constructor & Destructor Documentation

◆ Sandbox() [1/2]

Sandbox::Sandbox ( )

Definition at line 58 of file sandbox.cpp.

◆ Sandbox() [2/2]

Sandbox::Sandbox ( const QString & sandboxPath,
Usage usage,
Scopes scopes )

Definition at line 68 of file sandbox.cpp.

◆ ~Sandbox()

Sandbox::~Sandbox ( )

Definition at line 75 of file sandbox.cpp.

Member Function Documentation

◆ activate()

bool Sandbox::activate ( )

Definition at line 93 of file sandbox.cpp.

◆ addWorldFile()

bool Sandbox::addWorldFile ( const QString & file)

Definition at line 227 of file sandbox.cpp.

◆ addWorldFiles()

bool Sandbox::addWorldFiles ( const QString & directory,
QDir::Filters filters = QDir::NoFilter,
const QStringList & filterNames = QStringList(),
bool recurse = true )

Copies selected files into sandbox. Existing files in sandbox are not overwriten.

QDir::NoDotAndDotDot is always added into filters.

Definition at line 146 of file sandbox.cpp.

◆ deactivate()

void Sandbox::deactivate ( )

Definition at line 109 of file sandbox.cpp.

◆ effectiveRootDir()

QDir Sandbox::effectiveRootDir ( )
static

Definition at line 120 of file sandbox.cpp.

◆ isActive()

bool Sandbox::isActive ( ) const

Definition at line 88 of file sandbox.cpp.

◆ map() [1/2]

QString Sandbox::map ( const QString & fileName)
static

Definition at line 127 of file sandbox.cpp.

◆ map() [2/2]

QString Sandbox::map ( const QString & pathName,
const QString & fileName )
static

Definition at line 134 of file sandbox.cpp.


The documentation for this class was generated from the following files: