ssu
Public Types | Public Member Functions | Static Public Member Functions | List of all members
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 Function Documentation

◆ 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.


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