forked from qt-creator/qt-creator
RsyncDeployService: Reuse TaskTree
Change-Id: I411726e47550da5fd3269fcbb3e4f3e19096adeb Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -50,9 +50,16 @@ class PROJECTEXPLORER_EXPORT FileTransferAdapter : public Utils::Tasking::TaskAd
|
||||
{
|
||||
public:
|
||||
FileTransferAdapter();
|
||||
void start() override { task()->start(); }
|
||||
};
|
||||
|
||||
class PROJECTEXPLORER_EXPORT FileTransferTestAdapter : public FileTransferAdapter
|
||||
{
|
||||
public:
|
||||
void start() final { task()->test(); }
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
QTC_DECLARE_CUSTOM_TASK(Transfer, ProjectExplorer::FileTransferAdapter);
|
||||
QTC_DECLARE_CUSTOM_TASK(TransferTest, ProjectExplorer::FileTransferTestAdapter);
|
||||
|
@@ -181,7 +181,7 @@ TaskItem GenericLinuxDeviceTesterPrivate::transferTask(FileTransferMethod method
|
||||
"is not available.\n").arg(sftp, rsync));
|
||||
}
|
||||
};
|
||||
return Transfer(setup, done, error);
|
||||
return TransferTest(setup, done, error);
|
||||
}
|
||||
|
||||
TaskItem GenericLinuxDeviceTesterPrivate::transferTasks()
|
||||
|
@@ -23,65 +23,28 @@
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
using namespace Utils::Tasking;
|
||||
|
||||
namespace RemoteLinux {
|
||||
|
||||
class RsyncDeployService : public AbstractRemoteLinuxDeployService
|
||||
{
|
||||
public:
|
||||
RsyncDeployService()
|
||||
{
|
||||
connect(&m_mkdir, &QtcProcess::done, this, [this] {
|
||||
if (m_mkdir.result() != ProcessResult::FinishedWithSuccess) {
|
||||
QString finalMessage = m_mkdir.errorString();
|
||||
const QString stdErr = m_mkdir.cleanedStdErr();
|
||||
if (!stdErr.isEmpty()) {
|
||||
if (!finalMessage.isEmpty())
|
||||
finalMessage += '\n';
|
||||
finalMessage += stdErr;
|
||||
}
|
||||
emit errorMessage(Tr::tr("Deploy via rsync: failed to create remote directories:")
|
||||
+ '\n' + finalMessage);
|
||||
stopDeployment();
|
||||
return;
|
||||
}
|
||||
deployFiles();
|
||||
});
|
||||
connect(&m_mkdir, &QtcProcess::readyReadStandardError, this, [this] {
|
||||
emit stdErrData(QString::fromLocal8Bit(m_mkdir.readAllStandardError()));
|
||||
});
|
||||
connect(&m_fileTransfer, &FileTransfer::progress,
|
||||
this, &AbstractRemoteLinuxDeployService::stdOutData);
|
||||
connect(&m_fileTransfer, &FileTransfer::done, this, [this](const ProcessResultData &result) {
|
||||
if (result.m_error == QProcess::FailedToStart)
|
||||
emit errorMessage(Tr::tr("rsync failed to start: %1").arg(result.m_errorString));
|
||||
else if (result.m_exitStatus == QProcess::CrashExit)
|
||||
emit errorMessage(Tr::tr("rsync crashed."));
|
||||
else if (result.m_exitCode != 0)
|
||||
emit errorMessage(Tr::tr("rsync failed with exit code %1.").arg(result.m_exitCode));
|
||||
|
||||
stopDeployment();
|
||||
});
|
||||
}
|
||||
|
||||
void setDeployableFiles(const QList<DeployableFile> &files);
|
||||
void setIgnoreMissingFiles(bool ignore) { m_ignoreMissingFiles = ignore; }
|
||||
void setFlags(const QString &flags) { m_flags = flags; }
|
||||
|
||||
private:
|
||||
bool isDeploymentNecessary() const override;
|
||||
|
||||
void doDeploy() override;
|
||||
void stopDeployment() override;
|
||||
|
||||
void createRemoteDirectories();
|
||||
void deployFiles();
|
||||
TaskItem mkdirTask();
|
||||
TaskItem transferTask();
|
||||
|
||||
mutable FilesToTransfer m_files;
|
||||
bool m_ignoreMissingFiles = false;
|
||||
QString m_flags;
|
||||
QtcProcess m_mkdir;
|
||||
FileTransfer m_fileTransfer;
|
||||
std::unique_ptr<TaskTree> m_taskTree;
|
||||
};
|
||||
|
||||
void RsyncDeployService::setDeployableFiles(const QList<DeployableFile> &files)
|
||||
@@ -98,35 +61,76 @@ bool RsyncDeployService::isDeploymentNecessary() const
|
||||
return !m_files.empty();
|
||||
}
|
||||
|
||||
void RsyncDeployService::doDeploy()
|
||||
{
|
||||
createRemoteDirectories();
|
||||
}
|
||||
|
||||
void RsyncDeployService::createRemoteDirectories()
|
||||
TaskItem RsyncDeployService::mkdirTask()
|
||||
{
|
||||
auto setupHandler = [this](QtcProcess &process) {
|
||||
QStringList remoteDirs;
|
||||
for (const FileToTransfer &file : std::as_const(m_files))
|
||||
remoteDirs << file.m_target.parentDir().path();
|
||||
remoteDirs.sort();
|
||||
remoteDirs.removeDuplicates();
|
||||
|
||||
m_mkdir.setCommand({deviceConfiguration()->filePath("mkdir"), QStringList("-p") + remoteDirs});
|
||||
m_mkdir.start();
|
||||
process.setCommand({deviceConfiguration()->filePath("mkdir"),
|
||||
QStringList("-p") + remoteDirs});
|
||||
connect(&process, &QtcProcess::readyReadStandardError, this, [this, proc = &process] {
|
||||
emit stdErrData(QString::fromLocal8Bit(proc->readAllStandardError()));
|
||||
});
|
||||
};
|
||||
auto errorHandler = [this](const QtcProcess &process) {
|
||||
QString finalMessage = process.errorString();
|
||||
const QString stdErr = process.cleanedStdErr();
|
||||
if (!stdErr.isEmpty()) {
|
||||
if (!finalMessage.isEmpty())
|
||||
finalMessage += '\n';
|
||||
finalMessage += stdErr;
|
||||
}
|
||||
emit errorMessage(Tr::tr("Deploy via rsync: failed to create remote directories:")
|
||||
+ '\n' + finalMessage);
|
||||
};
|
||||
return Process(setupHandler, {}, errorHandler);
|
||||
}
|
||||
|
||||
void RsyncDeployService::deployFiles()
|
||||
TaskItem RsyncDeployService::transferTask()
|
||||
{
|
||||
m_fileTransfer.setTransferMethod(FileTransferMethod::Rsync);
|
||||
m_fileTransfer.setRsyncFlags(m_flags);
|
||||
m_fileTransfer.setFilesToTransfer(m_files);
|
||||
m_fileTransfer.start();
|
||||
auto setupHandler = [this](FileTransfer &transfer) {
|
||||
transfer.setTransferMethod(FileTransferMethod::Rsync);
|
||||
transfer.setRsyncFlags(m_flags);
|
||||
transfer.setFilesToTransfer(m_files);
|
||||
connect(&transfer, &FileTransfer::progress,
|
||||
this, &AbstractRemoteLinuxDeployService::stdOutData);
|
||||
};
|
||||
auto errorHandler = [this](const FileTransfer &transfer) {
|
||||
const ProcessResultData result = transfer.resultData();
|
||||
if (result.m_error == QProcess::FailedToStart)
|
||||
emit errorMessage(Tr::tr("rsync failed to start: %1").arg(result.m_errorString));
|
||||
else if (result.m_exitStatus == QProcess::CrashExit)
|
||||
emit errorMessage(Tr::tr("rsync crashed."));
|
||||
else if (result.m_exitCode != 0)
|
||||
emit errorMessage(Tr::tr("rsync failed with exit code %1.").arg(result.m_exitCode));
|
||||
};
|
||||
return Transfer(setupHandler, {}, errorHandler);
|
||||
}
|
||||
|
||||
void RsyncDeployService::doDeploy()
|
||||
{
|
||||
auto finishHandler = [this] {
|
||||
m_taskTree.release()->deleteLater();
|
||||
stopDeployment();
|
||||
};
|
||||
|
||||
Group root {
|
||||
mkdirTask(),
|
||||
transferTask(),
|
||||
OnGroupDone(finishHandler),
|
||||
OnGroupError(finishHandler),
|
||||
};
|
||||
|
||||
m_taskTree.reset(new TaskTree(root));
|
||||
m_taskTree->start();
|
||||
}
|
||||
|
||||
void RsyncDeployService::stopDeployment()
|
||||
{
|
||||
m_mkdir.close();
|
||||
m_fileTransfer.stop();
|
||||
m_taskTree.reset();
|
||||
handleDeploymentDone();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user