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:
Jarek Kobus
2022-05-16 17:24:36 +02:00
parent 13bfb06581
commit 80ae9c357d
2 changed files with 39 additions and 22 deletions

View File

@@ -71,6 +71,7 @@ public:
void setFilesToTransfer(const FilesToTransfer &files);
void setRsyncFlags(const QString &flags);
void test();
void start();
void stop();

View File

@@ -1529,7 +1529,7 @@ protected:
IDevice::ConstPtr m_device;
FilesToTransfer m_files;
QtcProcess m_process;
TransferDirection m_direction;
TransferDirection m_direction = TransferDirection::Invalid;
private:
virtual void startImpl() = 0;
@@ -1619,7 +1619,7 @@ private:
void doneImpl()
{
if (m_currentIndex == m_files.count() - 1)
if (m_files.size() == 0 || m_currentIndex == m_files.size() - 1)
return handleDone();
if (handleError())
@@ -1642,11 +1642,16 @@ private:
const QStringList options{"-e", sshCmdLine, m_flags};
const QString remoteHost = parameters.userName() + '@' + parameters.host();
QStringList args = QStringList(options);
if (!m_files.isEmpty()) { // NormalRun
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?
m_process.setCommand(CommandLine("rsync", args));
m_process.start();
@@ -1705,15 +1710,22 @@ public:
void setFilesToTransfer(const FilesToTransfer &files) { m_files = files; }
void setRsyncFlags(const QString &flags) { m_rsyncFlags = flags; }
void start();
void stop();
void test() { run(TestRun); }
void start() { run(NormalRun); }
void stop() { m_transfer.reset(); }
signals:
void progress(const QString &progressMessage);
void done(const Utils::ProcessResultData &resultData);
private:
enum RunMode {
NormalRun,
TestRun
};
void startFailed(const QString &errorString);
void run(RunMode mode);
FileTransferMethod m_method = FileTransferMethod::Default;
IDevice::ConstPtr m_device;
@@ -1723,19 +1735,22 @@ private:
std::unique_ptr<FileTransferInterface> m_transfer;
};
void FileTransferPrivate::start()
void FileTransferPrivate::run(RunMode mode)
{
stop();
TransferDirection direction = TransferDirection::Invalid;
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)
return startFailed(tr("Mixing different types on transfer in one go."));
if (!isDeviceMatched(m_files, m_device->id().toString()))
return startFailed(tr("Trying to transfer into / from not matching device."));
}
switch (m_method) {
case FileTransferMethod::Sftp:
@@ -1747,6 +1762,7 @@ void FileTransferPrivate::start()
}
QTC_ASSERT(m_transfer, startFailed(tr("Missing transfer implementation.")));
m_transfer->setDevice(m_device);
if (mode == NormalRun)
m_transfer->setFilesToTransfer(m_files, direction);
connect(m_transfer.get(), &FileTransferInterface::progress,
this, &FileTransferPrivate::progress);
@@ -1755,11 +1771,6 @@ void FileTransferPrivate::start()
m_transfer->start();
}
void FileTransferPrivate::stop()
{
m_transfer.reset();
}
void FileTransferPrivate::startFailed(const QString &errorString)
{
emit done({0, QProcess::NormalExit, QProcess::FailedToStart, errorString});
@@ -1799,6 +1810,11 @@ void FileTransfer::setRsyncFlags(const QString &flags)
d->setRsyncFlags(flags);
}
void FileTransfer::test()
{
d->test();
}
void FileTransfer::start()
{
d->start();