forked from qt-creator/qt-creator
FileTransfer: Add test() method
The test() method doesn't try to transfer anything, it just tests if the transfer itself work. In contrast to start() method, the FilesToTransfer list may be empty and test() method will not issue an assert. Change-Id: I719cfbaddc5e33d6a7cc660ef6aa0bbcb61c5bce Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -71,6 +71,7 @@ public:
|
|||||||
void setFilesToTransfer(const FilesToTransfer &files);
|
void setFilesToTransfer(const FilesToTransfer &files);
|
||||||
void setRsyncFlags(const QString &flags);
|
void setRsyncFlags(const QString &flags);
|
||||||
|
|
||||||
|
void test();
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
@@ -1529,7 +1529,7 @@ protected:
|
|||||||
IDevice::ConstPtr m_device;
|
IDevice::ConstPtr m_device;
|
||||||
FilesToTransfer m_files;
|
FilesToTransfer m_files;
|
||||||
QtcProcess m_process;
|
QtcProcess m_process;
|
||||||
TransferDirection m_direction;
|
TransferDirection m_direction = TransferDirection::Invalid;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void startImpl() = 0;
|
virtual void startImpl() = 0;
|
||||||
@@ -1619,7 +1619,7 @@ private:
|
|||||||
|
|
||||||
void doneImpl()
|
void doneImpl()
|
||||||
{
|
{
|
||||||
if (m_currentIndex == m_files.count() - 1)
|
if (m_files.size() == 0 || m_currentIndex == m_files.size() - 1)
|
||||||
return handleDone();
|
return handleDone();
|
||||||
|
|
||||||
if (handleError())
|
if (handleError())
|
||||||
@@ -1642,11 +1642,16 @@ private:
|
|||||||
const QStringList options{"-e", sshCmdLine, m_flags};
|
const QStringList options{"-e", sshCmdLine, m_flags};
|
||||||
const QString remoteHost = parameters.userName() + '@' + parameters.host();
|
const QString remoteHost = parameters.userName() + '@' + parameters.host();
|
||||||
|
|
||||||
const FileToTransfer file = m_files.at(m_currentIndex);
|
QStringList args = QStringList(options);
|
||||||
const FileToTransfer fixedFile = fixLocalFileOnWindows(file, options);
|
if (!m_files.isEmpty()) { // NormalRun
|
||||||
const auto fixedPaths = fixPaths(fixedFile, remoteHost);
|
const FileToTransfer file = m_files.at(m_currentIndex);
|
||||||
|
const FileToTransfer fixedFile = fixLocalFileOnWindows(file, options);
|
||||||
|
const auto fixedPaths = fixPaths(fixedFile, remoteHost);
|
||||||
|
|
||||||
const QStringList args = QStringList(options) << fixedPaths.first << fixedPaths.second;
|
args << fixedPaths.first << fixedPaths.second;
|
||||||
|
} else { // TestRun
|
||||||
|
args << "-n" << "--exclude=*" << (remoteHost + ":/tmp");
|
||||||
|
}
|
||||||
// TODO: Get rsync location from settings?
|
// TODO: Get rsync location from settings?
|
||||||
m_process.setCommand(CommandLine("rsync", args));
|
m_process.setCommand(CommandLine("rsync", args));
|
||||||
m_process.start();
|
m_process.start();
|
||||||
@@ -1705,15 +1710,22 @@ public:
|
|||||||
void setFilesToTransfer(const FilesToTransfer &files) { m_files = files; }
|
void setFilesToTransfer(const FilesToTransfer &files) { m_files = files; }
|
||||||
void setRsyncFlags(const QString &flags) { m_rsyncFlags = flags; }
|
void setRsyncFlags(const QString &flags) { m_rsyncFlags = flags; }
|
||||||
|
|
||||||
void start();
|
void test() { run(TestRun); }
|
||||||
void stop();
|
void start() { run(NormalRun); }
|
||||||
|
void stop() { m_transfer.reset(); }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void progress(const QString &progressMessage);
|
void progress(const QString &progressMessage);
|
||||||
void done(const Utils::ProcessResultData &resultData);
|
void done(const Utils::ProcessResultData &resultData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum RunMode {
|
||||||
|
NormalRun,
|
||||||
|
TestRun
|
||||||
|
};
|
||||||
|
|
||||||
void startFailed(const QString &errorString);
|
void startFailed(const QString &errorString);
|
||||||
|
void run(RunMode mode);
|
||||||
|
|
||||||
FileTransferMethod m_method = FileTransferMethod::Default;
|
FileTransferMethod m_method = FileTransferMethod::Default;
|
||||||
IDevice::ConstPtr m_device;
|
IDevice::ConstPtr m_device;
|
||||||
@@ -1723,19 +1735,22 @@ private:
|
|||||||
std::unique_ptr<FileTransferInterface> m_transfer;
|
std::unique_ptr<FileTransferInterface> m_transfer;
|
||||||
};
|
};
|
||||||
|
|
||||||
void FileTransferPrivate::start()
|
void FileTransferPrivate::run(RunMode mode)
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
if (m_files.isEmpty())
|
TransferDirection direction = TransferDirection::Invalid;
|
||||||
return startFailed(tr("No files to transfer."));
|
if (mode == NormalRun) {
|
||||||
|
if (m_files.isEmpty())
|
||||||
|
return startFailed(tr("No files to transfer."));
|
||||||
|
|
||||||
const TransferDirection direction = transferDirection(m_files);
|
direction = transferDirection(m_files);
|
||||||
if (direction == TransferDirection::Invalid)
|
if (direction == TransferDirection::Invalid)
|
||||||
return startFailed(tr("Mixing different types on transfer in one go."));
|
return startFailed(tr("Mixing different types on transfer in one go."));
|
||||||
|
|
||||||
if (!isDeviceMatched(m_files, m_device->id().toString()))
|
if (!isDeviceMatched(m_files, m_device->id().toString()))
|
||||||
return startFailed(tr("Trying to transfer into / from not matching device."));
|
return startFailed(tr("Trying to transfer into / from not matching device."));
|
||||||
|
}
|
||||||
|
|
||||||
switch (m_method) {
|
switch (m_method) {
|
||||||
case FileTransferMethod::Sftp:
|
case FileTransferMethod::Sftp:
|
||||||
@@ -1747,7 +1762,8 @@ void FileTransferPrivate::start()
|
|||||||
}
|
}
|
||||||
QTC_ASSERT(m_transfer, startFailed(tr("Missing transfer implementation.")));
|
QTC_ASSERT(m_transfer, startFailed(tr("Missing transfer implementation.")));
|
||||||
m_transfer->setDevice(m_device);
|
m_transfer->setDevice(m_device);
|
||||||
m_transfer->setFilesToTransfer(m_files, direction);
|
if (mode == NormalRun)
|
||||||
|
m_transfer->setFilesToTransfer(m_files, direction);
|
||||||
connect(m_transfer.get(), &FileTransferInterface::progress,
|
connect(m_transfer.get(), &FileTransferInterface::progress,
|
||||||
this, &FileTransferPrivate::progress);
|
this, &FileTransferPrivate::progress);
|
||||||
connect(m_transfer.get(), &FileTransferInterface::done,
|
connect(m_transfer.get(), &FileTransferInterface::done,
|
||||||
@@ -1755,11 +1771,6 @@ void FileTransferPrivate::start()
|
|||||||
m_transfer->start();
|
m_transfer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileTransferPrivate::stop()
|
|
||||||
{
|
|
||||||
m_transfer.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileTransferPrivate::startFailed(const QString &errorString)
|
void FileTransferPrivate::startFailed(const QString &errorString)
|
||||||
{
|
{
|
||||||
emit done({0, QProcess::NormalExit, QProcess::FailedToStart, errorString});
|
emit done({0, QProcess::NormalExit, QProcess::FailedToStart, errorString});
|
||||||
@@ -1799,6 +1810,11 @@ void FileTransfer::setRsyncFlags(const QString &flags)
|
|||||||
d->setRsyncFlags(flags);
|
d->setRsyncFlags(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileTransfer::test()
|
||||||
|
{
|
||||||
|
d->test();
|
||||||
|
}
|
||||||
|
|
||||||
void FileTransfer::start()
|
void FileTransfer::start()
|
||||||
{
|
{
|
||||||
d->start();
|
d->start();
|
||||||
|
Reference in New Issue
Block a user