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:
|
public:
|
||||||
FileTransferAdapter();
|
FileTransferAdapter();
|
||||||
|
void start() override { task()->start(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
class PROJECTEXPLORER_EXPORT FileTransferTestAdapter : public FileTransferAdapter
|
||||||
|
{
|
||||||
|
public:
|
||||||
void start() final { task()->test(); }
|
void start() final { task()->test(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
QTC_DECLARE_CUSTOM_TASK(Transfer, ProjectExplorer::FileTransferAdapter);
|
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));
|
"is not available.\n").arg(sftp, rsync));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return Transfer(setup, done, error);
|
return TransferTest(setup, done, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskItem GenericLinuxDeviceTesterPrivate::transferTasks()
|
TaskItem GenericLinuxDeviceTesterPrivate::transferTasks()
|
||||||
|
@@ -23,65 +23,28 @@
|
|||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
using namespace Utils::Tasking;
|
||||||
|
|
||||||
namespace RemoteLinux {
|
namespace RemoteLinux {
|
||||||
|
|
||||||
class RsyncDeployService : public AbstractRemoteLinuxDeployService
|
class RsyncDeployService : public AbstractRemoteLinuxDeployService
|
||||||
{
|
{
|
||||||
public:
|
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 setDeployableFiles(const QList<DeployableFile> &files);
|
||||||
void setIgnoreMissingFiles(bool ignore) { m_ignoreMissingFiles = ignore; }
|
void setIgnoreMissingFiles(bool ignore) { m_ignoreMissingFiles = ignore; }
|
||||||
void setFlags(const QString &flags) { m_flags = flags; }
|
void setFlags(const QString &flags) { m_flags = flags; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isDeploymentNecessary() const override;
|
bool isDeploymentNecessary() const override;
|
||||||
|
|
||||||
void doDeploy() override;
|
void doDeploy() override;
|
||||||
void stopDeployment() override;
|
void stopDeployment() override;
|
||||||
|
TaskItem mkdirTask();
|
||||||
void createRemoteDirectories();
|
TaskItem transferTask();
|
||||||
void deployFiles();
|
|
||||||
|
|
||||||
mutable FilesToTransfer m_files;
|
mutable FilesToTransfer m_files;
|
||||||
bool m_ignoreMissingFiles = false;
|
bool m_ignoreMissingFiles = false;
|
||||||
QString m_flags;
|
QString m_flags;
|
||||||
QtcProcess m_mkdir;
|
std::unique_ptr<TaskTree> m_taskTree;
|
||||||
FileTransfer m_fileTransfer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void RsyncDeployService::setDeployableFiles(const QList<DeployableFile> &files)
|
void RsyncDeployService::setDeployableFiles(const QList<DeployableFile> &files)
|
||||||
@@ -98,35 +61,76 @@ bool RsyncDeployService::isDeploymentNecessary() const
|
|||||||
return !m_files.empty();
|
return !m_files.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskItem RsyncDeployService::transferTask()
|
||||||
|
{
|
||||||
|
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()
|
void RsyncDeployService::doDeploy()
|
||||||
{
|
{
|
||||||
createRemoteDirectories();
|
auto finishHandler = [this] {
|
||||||
}
|
m_taskTree.release()->deleteLater();
|
||||||
|
stopDeployment();
|
||||||
|
};
|
||||||
|
|
||||||
void RsyncDeployService::createRemoteDirectories()
|
Group root {
|
||||||
{
|
mkdirTask(),
|
||||||
QStringList remoteDirs;
|
transferTask(),
|
||||||
for (const FileToTransfer &file : std::as_const(m_files))
|
OnGroupDone(finishHandler),
|
||||||
remoteDirs << file.m_target.parentDir().path();
|
OnGroupError(finishHandler),
|
||||||
remoteDirs.sort();
|
};
|
||||||
remoteDirs.removeDuplicates();
|
|
||||||
|
|
||||||
m_mkdir.setCommand({deviceConfiguration()->filePath("mkdir"), QStringList("-p") + remoteDirs});
|
m_taskTree.reset(new TaskTree(root));
|
||||||
m_mkdir.start();
|
m_taskTree->start();
|
||||||
}
|
|
||||||
|
|
||||||
void RsyncDeployService::deployFiles()
|
|
||||||
{
|
|
||||||
m_fileTransfer.setTransferMethod(FileTransferMethod::Rsync);
|
|
||||||
m_fileTransfer.setRsyncFlags(m_flags);
|
|
||||||
m_fileTransfer.setFilesToTransfer(m_files);
|
|
||||||
m_fileTransfer.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsyncDeployService::stopDeployment()
|
void RsyncDeployService::stopDeployment()
|
||||||
{
|
{
|
||||||
m_mkdir.close();
|
m_taskTree.reset();
|
||||||
m_fileTransfer.stop();
|
|
||||||
handleDeploymentDone();
|
handleDeploymentDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user