Navigation Menu

Skip to content

Commit

Permalink
Implement in-process directory copy
Browse files Browse the repository at this point in the history
  • Loading branch information
martyone authored and Bernd Wachter committed May 27, 2013
1 parent 0c50437 commit 652f343
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
39 changes: 38 additions & 1 deletion libssu/sandbox.cpp
Expand Up @@ -10,6 +10,7 @@
#include <stdlib.h>

#include <QtCore/QDir>
#include <QtCore/QDirIterator>
#include <QtCore/QFileInfo>
#include <QtCore/QProcessEnvironment>
#include <QtCore/QSet>
Expand Down Expand Up @@ -252,7 +253,7 @@ bool Sandbox::prepare(){

const QString sandboxCopyPath = QDir(m_tempDir).filePath("configroot");

if (QProcess::execute("cp", QStringList() << "-r" << m_sandboxPath << sandboxCopyPath) != 0){
if (!copyDir(m_sandboxPath, sandboxCopyPath)){
qWarning("%s: Failed to copy sandbox directory", Q_FUNC_INFO);
return false;
}
Expand All @@ -265,3 +266,39 @@ bool Sandbox::prepare(){
m_prepared = true;
return true;
}

bool Sandbox::copyDir(const QString &directory, const QString &newName){
const QDir sourceRoot(directory);
const QDir destinationRoot(newName);

QDirIterator it(directory, QDir::AllEntries|QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (it.hasNext()){
it.next();

const QFileInfo destination = QFileInfo(destinationRoot.filePath(
sourceRoot.relativeFilePath(it.filePath())));

if (it.fileInfo().isDir()){
if (!QDir().mkpath(destination.absoluteFilePath())){
qWarning("%s: Failed to mkpath '%s'", Q_FUNC_INFO, qPrintable(destination.absolutePath()));
return false;
}
} else if (it.fileInfo().isFile()){
if (!QDir().mkpath(destination.absolutePath())){
qWarning("%s: Failed to mkpath '%s'", Q_FUNC_INFO, qPrintable(destination.absolutePath()));
return false;
}

if (!QFile::copy(it.fileInfo().absoluteFilePath(), destination.absoluteFilePath())){
qWarning("%s: Failed to copy file '%s'", Q_FUNC_INFO, qPrintable(it.filePath()));
return false;
}
} else{
qWarning("%s: Cannot copy other than regular files: '%s'", Q_FUNC_INFO,
qPrintable(it.filePath()));
return false;
}
}

return true;
}
1 change: 1 addition & 0 deletions libssu/sandbox_p.h
Expand Up @@ -43,6 +43,7 @@ class Sandbox {

private:
bool prepare();
static bool copyDir(const QString &directory, const QString &newName);

private:
static Sandbox *s_activeInstance;
Expand Down

0 comments on commit 652f343

Please sign in to comment.