Commit 8b124190 authored by Martin Kampas's avatar Martin Kampas

Sandbox: allow to control the scope of action

parent ea672d43
......@@ -7,6 +7,8 @@
#include "sandbox_p.h"
#include <stdlib.h>
#include <QtCore/QAbstractFileEngineHandler>
#include <QtCore/QDir>
#include <QtCore/QFSFileEngine>
......@@ -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.
*/
......@@ -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);
}
......@@ -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(){
......
......@@ -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:
......@@ -34,4 +40,6 @@ class Sandbox {
FileEngineHandler *m_handler;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Sandbox::Scopes)
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment