CopyStepBase: Employ task tree for running

Task-number: QTCREATORBUG-29168
Change-Id: Ie97c20da77ca8b1d93bf4725fa5bd4a7710be55b
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-07-13 00:04:11 +02:00
parent d7a232331a
commit 870a1dca4d

View File

@@ -7,7 +7,9 @@
#include "projectexplorertr.h" #include "projectexplorertr.h"
#include <utils/aspects.h> #include <utils/aspects.h>
#include <utils/filestreamer.h>
using namespace Tasking;
using namespace Utils; using namespace Utils;
namespace ProjectExplorer::Internal { namespace ProjectExplorer::Internal {
@@ -33,31 +35,34 @@ public:
protected: protected:
bool init() final bool init() final
{ {
if (!BuildStep::init())
return false;
m_source = m_sourceAspect(); m_source = m_sourceAspect();
m_target = m_targetAspect(); m_target = m_targetAspect();
return m_source.exists(); return m_source.exists();
} }
void doRun() final
{
// FIXME: asyncCopy does not handle directories yet.
QTC_ASSERT(m_source.isFile(), emit finished(false));
m_source.asyncCopy(m_target, this, [this](const expected_str<void> &cont) {
if (!cont) {
addOutput(cont.error(), OutputFormat::ErrorMessage);
addOutput(Tr::tr("Copying failed."), OutputFormat::ErrorMessage);
emit finished(false);
} else {
addOutput(Tr::tr("Copying finished."), OutputFormat::NormalMessage);
emit finished(true);
}
});
}
FilePathAspect m_sourceAspect{this}; FilePathAspect m_sourceAspect{this};
FilePathAspect m_targetAspect{this}; FilePathAspect m_targetAspect{this};
private: private:
GroupItem runRecipe() final
{
const auto onSetup = [this](FileStreamer &streamer) {
QTC_ASSERT(m_source.isFile(), return SetupResult::StopWithError);
streamer.setSource(m_source);
streamer.setDestination(m_target);
return SetupResult::Continue;
};
const auto onDone = [this](const FileStreamer &) {
addOutput(Tr::tr("Copying finished."), OutputFormat::NormalMessage);
};
const auto onError = [this](const FileStreamer &) {
addOutput(Tr::tr("Copying failed."), OutputFormat::ErrorMessage);
};
return FileStreamerTask(onSetup, onDone, onError);
}
FilePath m_source; FilePath m_source;
FilePath m_target; FilePath m_target;
}; };