Commit 1cfaa301 authored by Martin Kampas's avatar Martin Kampas Committed by Aard

Implement in-process tmp dir creation

parent 652f343f
......@@ -238,19 +238,11 @@ bool Sandbox::prepare(){
}
if (m_usage == UseAsSkeleton){
QProcess mktemp;
mktemp.start("mktemp", QStringList() << "-t" << "-d" << "ssu-sandbox.XXX");
if (!mktemp.waitForFinished() || mktemp.exitCode() != 0){
if (m_tempDir = createTmpDir("ssu-sandbox.%1"), m_tempDir.isEmpty()){
qWarning("%s: Failed to create sandbox directory", Q_FUNC_INFO);
return false;
}
m_tempDir = mktemp.readAllStandardOutput().trimmed();
if (!QFileInfo(m_tempDir).isDir()){
qWarning("%s: Temporary directory disappeared: '%s'", Q_FUNC_INFO, qPrintable(m_tempDir));
return false;
}
const QString sandboxCopyPath = QDir(m_tempDir).filePath("configroot");
if (!copyDir(m_sandboxPath, sandboxCopyPath)){
......@@ -267,6 +259,25 @@ bool Sandbox::prepare(){
return true;
}
QString Sandbox::createTmpDir(const QString &nameTemplate){
static const int REASONABLE_REPEAT_COUNT = 10;
for (int i = 0; i < REASONABLE_REPEAT_COUNT; ++i){
QString path;
int suffix = 0;
do{
path = QDir::temp().filePath(nameTemplate.arg(++suffix));
}while(QFileInfo(path).exists());
if (QDir().mkpath(path)){
return path;
}
}
qWarning("%s: Failed to create temporary directory", Q_FUNC_INFO);
return QString();
}
bool Sandbox::copyDir(const QString &directory, const QString &newName){
const QDir sourceRoot(directory);
const QDir destinationRoot(newName);
......
......@@ -43,6 +43,7 @@ class Sandbox {
private:
bool prepare();
static QString createTmpDir(const QString &nameTemplate);
static bool copyDir(const QString &directory, const QString &newName);
private:
......
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