Skip to content

Commit

Permalink
Sandbox: allow to control the scope of action
Browse files Browse the repository at this point in the history
  • Loading branch information
martyone committed Apr 4, 2013
1 parent ea672d4 commit 8b12419
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
16 changes: 14 additions & 2 deletions libssu/sandbox.cpp
Expand Up @@ -7,6 +7,8 @@

#include "sandbox_p.h"

#include <stdlib.h>

#include <QtCore/QAbstractFileEngineHandler>
#include <QtCore/QDir>
#include <QtCore/QFSFileEngine>
Expand Down Expand Up @@ -39,6 +41,10 @@ class Sandbox::FileEngineHandler : public QAbstractFileEngineHandler {
* copy of @a sandboxPath to work on and files in the original directory will
* stay untouched.
*
* The argument @scopes allows to control if the sandbox will be used by this
* process, its children processes (@c SSU_TESTS_SANDBOX environment variable
* will be exported), or both.
*
* Internally it is based on QAbstractFileEngineHandler.
*/

Expand Down Expand Up @@ -81,7 +87,7 @@ Sandbox::Sandbox(){
m_handler = new FileEngineHandler(m_sandboxPath);
}

Sandbox::Sandbox(const QString &sandboxPath, Usage usage){
Sandbox::Sandbox(const QString &sandboxPath, Usage usage, Scopes scopes){
if (s_instance != 0){
qFatal("%s: Cannot be instantiated more than once", Q_FUNC_INFO);
}
Expand Down Expand Up @@ -128,7 +134,13 @@ Sandbox::Sandbox(const QString &sandboxPath, Usage usage){
m_sandboxPath = sandboxCopyPath;
}

m_handler = new FileEngineHandler(m_sandboxPath);
if (scopes & ThisProcess){
m_handler = new FileEngineHandler(m_sandboxPath);
}

if (scopes & ChildProcesses){
setenv("SSU_TESTS_SANDBOX", qPrintable(m_sandboxPath), 1);
}
}

Sandbox::~Sandbox(){
Expand Down
10 changes: 9 additions & 1 deletion libssu/sandbox_p.h
Expand Up @@ -20,9 +20,15 @@ class Sandbox {
UseAsSkeleton,
};

enum Scope {
ThisProcess = 0x01,
ChildProcesses = 0x02,
};
Q_DECLARE_FLAGS(Scopes, Scope)

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

private:
Expand All @@ -34,4 +40,6 @@ class Sandbox {
FileEngineHandler *m_handler;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Sandbox::Scopes)

#endif

0 comments on commit 8b12419

Please sign in to comment.