From 8b124190ae9b7723dc25d0ec8921d5a6bd8edbe6 Mon Sep 17 00:00:00 2001 From: Martin Kampas Date: Thu, 4 Apr 2013 14:18:44 +0200 Subject: [PATCH] Sandbox: allow to control the scope of action --- libssu/sandbox.cpp | 16 ++++++++++++++-- libssu/sandbox_p.h | 10 +++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/libssu/sandbox.cpp b/libssu/sandbox.cpp index cbbcd84..ce6139b 100644 --- a/libssu/sandbox.cpp +++ b/libssu/sandbox.cpp @@ -7,6 +7,8 @@ #include "sandbox_p.h" +#include + #include #include #include @@ -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(){ diff --git a/libssu/sandbox_p.h b/libssu/sandbox_p.h index 55d2880..146bdf7 100644 --- a/libssu/sandbox_p.h +++ b/libssu/sandbox_p.h @@ -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