From 79cacd354d8944b57b7d940ccb1cd5189e18a98d Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 19 May 2022 22:40:37 +0200 Subject: [PATCH] FileTransfer: Make it possible to call stop() from done() handler Don't delete the TransferInterface directly from stop(). Disconnect from it and delete it later. Fix emitting done() signal when error occurred. Fix passing the proper enum to RsyncTransferImpl. Set proper parent for TransferInterface. Change-Id: I430f0bf2507de8a9b7fb610641ca86e37ccd80d9 Reviewed-by: Qt CI Bot Reviewed-by: Christian Kandeler --- src/plugins/remotelinux/linuxdevice.cpp | 30 ++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 2c64e988fc9..52eeded36a4 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -1507,6 +1507,7 @@ protected: } else { return false; } + emit done(resultData); return true; } @@ -1597,7 +1598,7 @@ class RsyncTransferImpl : public FileTransferInterface { public: RsyncTransferImpl(const QString &flags) - : FileTransferInterface(FileTransferMethod::Sftp) + : FileTransferInterface(FileTransferMethod::Rsync) , m_flags(flags) { } @@ -1649,7 +1650,7 @@ private: } // On Windows, rsync is either from msys or cygwin. Neither work with the other's ssh.exe. - FileToTransfer fixLocalFileOnWindows(const FileToTransfer &file, const QStringList &options) + FileToTransfer fixLocalFileOnWindows(const FileToTransfer &file, const QStringList &options) const { if (!HostOsInfo::isWindowsHost()) return file; @@ -1668,7 +1669,7 @@ private: return fixedFile; } - QPair fixPaths(const FileToTransfer &file, const QString &remoteHost) + QPair fixPaths(const FileToTransfer &file, const QString &remoteHost) const { FilePath localPath; FilePath remotePath; @@ -1698,7 +1699,7 @@ class FileTransferPrivate : public QObject public: void test() { run(TestRun); } void start() { run(NormalRun); } - void stop() { m_transfer.reset(); } + void stop(); FileTransferMethod m_method = FileTransferMethod::Default; IDevice::ConstPtr m_device; @@ -1721,6 +1722,19 @@ private: std::unique_ptr m_transfer; }; +void FileTransferPrivate::stop() +{ + if (!m_transfer) + return; + m_transfer->disconnect(); + m_transfer.release()->deleteLater(); +} + +void FileTransferPrivate::startFailed(const QString &errorString) +{ + emit done({0, QProcess::NormalExit, QProcess::FailedToStart, errorString}); +} + void FileTransferPrivate::run(RunMode mode) { stop(); @@ -1746,7 +1760,8 @@ void FileTransferPrivate::run(RunMode mode) m_transfer.reset(new RsyncTransferImpl(m_rsyncFlags)); break; } - QTC_ASSERT(m_transfer, startFailed(tr("Missing transfer implementation."))); + QTC_ASSERT(m_transfer, startFailed(tr("Missing transfer implementation.")); return); + m_transfer->setParent(this); m_transfer->setDevice(m_device); if (mode == NormalRun) m_transfer->setFilesToTransfer(m_files, direction); @@ -1757,11 +1772,6 @@ void FileTransferPrivate::run(RunMode mode) m_transfer->start(); } -void FileTransferPrivate::startFailed(const QString &errorString) -{ - emit done({0, QProcess::NormalExit, QProcess::FailedToStart, errorString}); -} - FileTransfer::FileTransfer() : d(new FileTransferPrivate) {