diff options
author | Jarek Kobus <[email protected]> | 2022-05-11 17:28:41 +0200 |
---|---|---|
committer | Jarek Kobus <[email protected]> | 2022-05-23 11:51:35 +0000 |
commit | edd9ddcd758a2d17d65ad5cfca1736f267677b22 (patch) | |
tree | 5069242fecc7eec7f8c8c1f92c21c4404116a487 /src/libs/ssh | |
parent | 283cd4690ff5b37c5b12bc83cb237302c8b36722 (diff) |
Get rid of SftpTransfer
Remove also sftpdefs.h. They are not used anymore.
Change-Id: I6c45a70cec2e01afdd1a668068e090f5d4abde9b
Reviewed-by: Christian Kandeler <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
Diffstat (limited to 'src/libs/ssh')
-rw-r--r-- | src/libs/ssh/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/libs/ssh/sftpdefs.cpp | 28 | ||||
-rw-r--r-- | src/libs/ssh/sftpdefs.h | 71 | ||||
-rw-r--r-- | src/libs/ssh/sftptransfer.cpp | 189 | ||||
-rw-r--r-- | src/libs/ssh/sftptransfer.h | 61 | ||||
-rw-r--r-- | src/libs/ssh/ssh.qbs | 4 | ||||
-rw-r--r-- | src/libs/ssh/sshconnection.cpp | 21 | ||||
-rw-r--r-- | src/libs/ssh/sshconnection.h | 5 |
8 files changed, 0 insertions, 381 deletions
diff --git a/src/libs/ssh/CMakeLists.txt b/src/libs/ssh/CMakeLists.txt index 0358b30d1e2..b06e3b069fd 100644 --- a/src/libs/ssh/CMakeLists.txt +++ b/src/libs/ssh/CMakeLists.txt @@ -1,8 +1,6 @@ add_qtc_library(QtcSsh DEPENDS Qt5::Core Qt5::Network Qt5::Widgets Utils SOURCES - sftpdefs.cpp sftpdefs.h - sftptransfer.cpp sftptransfer.h ssh.qrc ssh_global.h sshconnection.cpp sshconnection.h diff --git a/src/libs/ssh/sftpdefs.cpp b/src/libs/ssh/sftpdefs.cpp deleted file mode 100644 index 1964e1e1fc2..00000000000 --- a/src/libs/ssh/sftpdefs.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "sftpdefs.h" - -namespace QSsh { const SftpJobId SftpInvalidJob = 0; } diff --git a/src/libs/ssh/sftpdefs.h b/src/libs/ssh/sftpdefs.h deleted file mode 100644 index ee5dd2dc3cb..00000000000 --- a/src/libs/ssh/sftpdefs.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "ssh_global.h" - -#include <QFile> -#include <QList> -#include <QString> - -#include <memory> - -namespace QSsh { - -class SftpTransfer; -using SftpTransferPtr = std::unique_ptr<SftpTransfer>; - -class FileToTransfer -{ -public: - FileToTransfer(const QString &source, const QString &target) - : sourceFile(source), targetFile(target) {} - QString sourceFile; - QString targetFile; -}; -using FilesToTransfer = QList<FileToTransfer>; - -namespace Internal { enum class FileTransferType { Upload, Download }; } - -typedef quint32 SftpJobId; -QSSH_EXPORT extern const SftpJobId SftpInvalidJob; - -enum SftpOverwriteMode { - SftpOverwriteExisting, SftpAppendToExisting, SftpSkipExisting -}; - -enum SftpFileType { FileTypeRegular, FileTypeDirectory, FileTypeOther, FileTypeUnknown }; - -class QSSH_EXPORT SftpFileInfo -{ -public: - QString name; - SftpFileType type = FileTypeUnknown; - quint64 size = 0; - QFile::Permissions permissions; -}; - -} // namespace QSsh diff --git a/src/libs/ssh/sftptransfer.cpp b/src/libs/ssh/sftptransfer.cpp deleted file mode 100644 index 2ee528356d9..00000000000 --- a/src/libs/ssh/sftptransfer.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "sftptransfer.h" - -#include "sshlogging_p.h" -#include "sshconnection.h" -#include "sshsettings.h" - -#include <QDir> -#include <QFileInfo> -#include <QStringList> -#include <QTemporaryFile> -#include <QTimer> - -#include <utils/algorithm.h> -#include <utils/commandline.h> -#include <utils/qtcprocess.h> - -using namespace Utils; - -namespace QSsh { - -struct SftpTransfer::SftpTransferPrivate -{ - QtcProcess sftpProc; - FilesToTransfer files; - Internal::FileTransferType transferType; - QStringList connectionArgs; - QString batchFilePath; - - QStringList dirsToCreate() const - { - QStringList dirs; - for (const FileToTransfer &f : qAsConst(files)) { - QString parentDir = QFileInfo(f.targetFile).path(); - while (true) { - if (dirs.contains(parentDir) || !parentDir.startsWith('/')) - break; - dirs << parentDir; - parentDir = QFileInfo(parentDir).path(); - } - } - sort(dirs, [](const QString &d1, const QString &d2) { - if (d1 == "/" && d2 != "/") - return true; - return d1.count('/') < d2.count('/'); - }); - return dirs; - } - QByteArray transferCommand(bool link) const - { - QByteArray command; - switch (transferType) { - case Internal::FileTransferType::Upload: - command = link ? "ln -s" : "put"; - break; - case Internal::FileTransferType::Download: - command = "get"; - break; - } - return command; - } -}; - -SftpTransfer::~SftpTransfer() -{ - if (!d->batchFilePath.isEmpty() && !QFile::remove(d->batchFilePath)) - qCWarning(Internal::sshLog) << "failed to remove batch file" << d->batchFilePath; - delete d; -} - -void SftpTransfer::start() -{ - QTimer::singleShot(0, this, &SftpTransfer::doStart); -} - -void SftpTransfer::stop() -{ - d->sftpProc.terminate(); -} - -SftpTransfer::SftpTransfer(const FilesToTransfer &files, Internal::FileTransferType type, - const QStringList &connectionArgs) - : d(new SftpTransferPrivate) -{ - SshConnectionParameters::setupSshEnvironment(&d->sftpProc); - d->files = files; - d->transferType = type; - d->connectionArgs = connectionArgs; - connect(&d->sftpProc, &QtcProcess::done, [this] { - if (d->sftpProc.error() == QProcess::FailedToStart) { - emitError(tr("sftp failed to start: %1").arg(d->sftpProc.errorString())); - return; - } - if (d->sftpProc.exitStatus() != QProcess::NormalExit) { - emitError(tr("sftp crashed.")); - return; - } - if (d->sftpProc.exitCode() != 0) { - emitError(QString::fromLocal8Bit(d->sftpProc.readAllStandardError())); - return; - } - emit done(QString()); - }); - connect(&d->sftpProc, &QtcProcess::readyReadStandardOutput, [this] { - emit progress(QString::fromLocal8Bit(d->sftpProc.readAllStandardOutput())); - }); -} - -void SftpTransfer::doStart() -{ - const FilePath sftpBinary = SshSettings::sftpFilePath(); - if (!sftpBinary.exists()) { - emitError(tr("sftp binary \"%1\" does not exist.").arg(sftpBinary.toUserOutput())); - return; - } - QTemporaryFile batchFile; - batchFile.setAutoRemove(false); - if (!batchFile.isOpen() && !batchFile.open()) { - emitError(tr("Could not create temporary file: %1").arg(batchFile.errorString())); - return; - } - d->batchFilePath = batchFile.fileName(); - batchFile.resize(0); - for (const QString &dir : d->dirsToCreate()) { - switch (d->transferType) { - case Internal::FileTransferType::Upload: - batchFile.write("-mkdir " + ProcessArgs::quoteArgUnix(dir).toLocal8Bit() + '\n'); - break; - case Internal::FileTransferType::Download: - if (!QDir::root().mkpath(dir)) { - emitError(tr("Failed to create local directory \"%1\".") - .arg(QDir::toNativeSeparators(dir))); - return; - } - break; - } - } - for (const FileToTransfer &f : qAsConst(d->files)) { - QString sourceFileOrLinkTarget = f.sourceFile; - bool link = false; - if (d->transferType == Internal::FileTransferType::Upload) { - QFileInfo fi(f.sourceFile); - if (fi.isSymLink()) { - link = true; - batchFile.write("-rm " + ProcessArgs::quoteArgUnix(f.targetFile).toLocal8Bit() - + '\n'); - sourceFileOrLinkTarget = fi.dir().relativeFilePath(fi.symLinkTarget()); // see QTBUG-5817. - } - } - batchFile.write(d->transferCommand(link) + ' ' - + ProcessArgs::quoteArgUnix(sourceFileOrLinkTarget).toLocal8Bit() + ' ' - + ProcessArgs::quoteArgUnix(f.targetFile).toLocal8Bit() + '\n'); - } - d->sftpProc.setStandardInputFile(batchFile.fileName()); - d->sftpProc.setCommand(CommandLine(sftpBinary, d->connectionArgs)); - d->sftpProc.start(); - emit started(); -} - -void SftpTransfer::emitError(const QString &details) -{ - emit done(tr("File transfer failed: %1").arg(details)); -} - -} // namespace QSsh diff --git a/src/libs/ssh/sftptransfer.h b/src/libs/ssh/sftptransfer.h deleted file mode 100644 index 1b46734f9e7..00000000000 --- a/src/libs/ssh/sftptransfer.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "sftpdefs.h" -#include "ssh_global.h" - -#include <QObject> - -namespace QSsh { -class SshConnection; - -class QSSH_EXPORT SftpTransfer : public QObject -{ - friend class SshConnection; - Q_OBJECT -public: - ~SftpTransfer(); - - void start(); - void stop(); - -signals: - void started(); - void done(const QString &error); - void progress(const QString &output); - -private: - SftpTransfer(const FilesToTransfer &files, Internal::FileTransferType type, - const QStringList &connectionArgs); - void doStart(); - void emitError(const QString &details); - - struct SftpTransferPrivate; - SftpTransferPrivate * const d; -}; - -} // namespace QSsh diff --git a/src/libs/ssh/ssh.qbs b/src/libs/ssh/ssh.qbs index 9f7c880b953..bd41f8dc661 100644 --- a/src/libs/ssh/ssh.qbs +++ b/src/libs/ssh/ssh.qbs @@ -17,10 +17,6 @@ Project { Depends { name: "Utils" } files: [ - "sftpdefs.cpp", - "sftpdefs.h", - "sftptransfer.cpp", - "sftptransfer.h", "ssh.qrc", "sshconnection.h", "sshconnection.cpp", diff --git a/src/libs/ssh/sshconnection.cpp b/src/libs/ssh/sshconnection.cpp index 8cd9f2431b8..0db38cf54cf 100644 --- a/src/libs/ssh/sshconnection.cpp +++ b/src/libs/ssh/sshconnection.cpp @@ -25,7 +25,6 @@ #include "sshconnection.h" -#include "sftptransfer.h" #include "sshlogging_p.h" #include "sshsettings.h" @@ -198,8 +197,6 @@ struct SshConnection::SshConnectionPrivate SshConnection::SshConnection(const SshConnectionParameters &serverInfo, QObject *parent) : QObject(parent), d(new SshConnectionPrivate(serverInfo)) { - qRegisterMetaType<QSsh::SftpFileInfo>("QSsh::SftpFileInfo"); - qRegisterMetaType<QList <QSsh::SftpFileInfo> >("QList<QSsh::SftpFileInfo>"); connect(&d->masterProcess, &QtcProcess::readyReadStandardOutput, [this] { const QByteArray reply = d->masterProcess.readAllStandardOutput(); if (reply == "\n") @@ -287,16 +284,6 @@ SshConnection::~SshConnection() delete d; } -SftpTransferPtr SshConnection::createUpload(const FilesToTransfer &files) -{ - return setupTransfer(files, Internal::FileTransferType::Upload); -} - -SftpTransferPtr SshConnection::createDownload(const FilesToTransfer &files) -{ - return setupTransfer(files, Internal::FileTransferType::Download); -} - void SshConnection::doConnectToHost() { if (d->state != Connecting) @@ -353,14 +340,6 @@ void SshConnection::emitDisconnected() emit disconnected(); } -SftpTransferPtr SshConnection::setupTransfer(const FilesToTransfer &files, - Internal::FileTransferType type) -{ - QTC_ASSERT(state() == Connected, return SftpTransferPtr()); - return SftpTransferPtr(new SftpTransfer(files, type, - d->connectionArgs(SshSettings::sftpFilePath()))); -} - #ifdef WITH_TESTS namespace SshTest { const QString getHostFromEnvironment() diff --git a/src/libs/ssh/sshconnection.h b/src/libs/ssh/sshconnection.h index 1b9c80e18dd..88b9951231f 100644 --- a/src/libs/ssh/sshconnection.h +++ b/src/libs/ssh/sshconnection.h @@ -25,7 +25,6 @@ #pragma once -#include "sftpdefs.h" #include "ssh_global.h" #include <utils/filepath.h> @@ -99,9 +98,6 @@ public: bool sharingEnabled() const; ~SshConnection(); - SftpTransferPtr createUpload(const FilesToTransfer &files); - SftpTransferPtr createDownload(const FilesToTransfer &files); - signals: void connected(); void disconnected(); @@ -112,7 +108,6 @@ private: void emitError(const QString &reason); void emitConnected(); void emitDisconnected(); - SftpTransferPtr setupTransfer(const FilesToTransfer &files, Internal::FileTransferType type); struct SshConnectionPrivate; SshConnectionPrivate * const d; |