feat: add dryRun to copy operation
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
parent
e048bce13e
commit
15aaff7c1c
@ -152,9 +152,10 @@ bool ensureFolderPathExists(QString foldernamepath)
|
||||
/// @brief Copies a directory and it's contents from src to dest
|
||||
/// @param offset subdirectory form src to copy to dest
|
||||
/// @return if there was an error during the filecopy
|
||||
bool copy::operator()(const QString& offset)
|
||||
bool copy::operator()(const QString& offset, bool dryRun)
|
||||
{
|
||||
using copy_opts = fs::copy_options;
|
||||
m_copied = 0; // reset counter
|
||||
|
||||
// NOTE always deep copy on windows. the alternatives are too messy.
|
||||
#if defined Q_OS_WIN32
|
||||
@ -178,9 +179,10 @@ bool copy::operator()(const QString& offset)
|
||||
return;
|
||||
|
||||
auto dst_path = PathCombine(dst, relative_dst_path);
|
||||
ensureFilePathExists(dst_path);
|
||||
|
||||
fs::copy(StringUtils::toStdString(src_path), StringUtils::toStdString(dst_path), opt, err);
|
||||
if (!dryRun) {
|
||||
ensureFilePathExists(dst_path);
|
||||
fs::copy(StringUtils::toStdString(src_path), StringUtils::toStdString(dst_path), opt, err);
|
||||
}
|
||||
if (err) {
|
||||
qWarning() << "Failed to copy files:" << QString::fromStdString(err.message());
|
||||
qDebug() << "Source file:" << src_path;
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
#include <QDir>
|
||||
#include <QFlags>
|
||||
#include <QObject>
|
||||
|
||||
namespace FS {
|
||||
|
||||
@ -76,9 +77,10 @@ bool ensureFilePathExists(QString filenamepath);
|
||||
bool ensureFolderPathExists(QString filenamepath);
|
||||
|
||||
/// @brief Copies a directory and it's contents from src to dest
|
||||
class copy {
|
||||
class copy : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
copy(const QString& src, const QString& dst)
|
||||
copy(const QString& src, const QString& dst, QObject* parent = nullptr) : QObject(parent)
|
||||
{
|
||||
m_src.setPath(src);
|
||||
m_dst.setPath(dst);
|
||||
@ -98,10 +100,17 @@ class copy {
|
||||
m_whitelist = whitelist;
|
||||
return *this;
|
||||
}
|
||||
bool operator()() { return operator()(QString()); }
|
||||
|
||||
bool operator()(bool dryRun = false) { return operator()(QString(), dryRun); }
|
||||
|
||||
int totalCopied() { return m_copied; }
|
||||
|
||||
signals:
|
||||
void fileCopied(const QString& relativeName);
|
||||
// TODO: maybe add a "shouldCopy" signal in the future?
|
||||
|
||||
private:
|
||||
bool operator()(const QString& offset);
|
||||
bool operator()(const QString& offset, bool dryRun = false);
|
||||
|
||||
private:
|
||||
bool m_followSymlinks = true;
|
||||
@ -109,6 +118,7 @@ class copy {
|
||||
bool m_whitelist = false;
|
||||
QDir m_src;
|
||||
QDir m_dst;
|
||||
int m_copied;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,9 @@ void InstanceCopyTask::executeTask()
|
||||
FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath);
|
||||
folderCopy.followSymlinks(false).matcher(m_matcher.get());
|
||||
|
||||
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), folderCopy);
|
||||
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [&folderCopy]{
|
||||
return folderCopy();
|
||||
});
|
||||
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::finished, this, &InstanceCopyTask::copyFinished);
|
||||
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::canceled, this, &InstanceCopyTask::copyAborted);
|
||||
m_copyFutureWatcher.setFuture(m_copyFuture);
|
||||
|
Loading…
Reference in New Issue
Block a user