diff options
-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 | ||||
-rw-r--r-- | tests/auto/ssh/tst_ssh.cpp | 37 |
9 files changed, 0 insertions, 418 deletions
diff --git a/src/libs/ssh/CMakeLists.txt b/src/libs/ssh/CMakeLists.txt index 0358b30d1e..b06e3b069f 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 1964e1e1fc..0000000000 --- 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 ee5dd2dc3c..0000000000 --- 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 2ee528356d..0000000000 --- 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 1b46734f9e..0000000000 --- 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 9f7c880b95..bd41f8dc66 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 8cd9f2431b..0db38cf54c 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 1b9c80e18d..88b9951231 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; diff --git a/tests/auto/ssh/tst_ssh.cpp b/tests/auto/ssh/tst_ssh.cpp index be06dde583..6e97b21888 100644 --- a/tests/auto/ssh/tst_ssh.cpp +++ b/tests/auto/ssh/tst_ssh.cpp @@ -23,7 +23,6 @@ ** ****************************************************************************/ -#include <ssh/sftptransfer.h> #include <ssh/sshconnection.h> #include <ssh/sshsettings.h> @@ -170,23 +169,6 @@ void tst_Ssh::sftp() QVERIFY2(dirForFilesToUpload.isValid(), qPrintable(dirForFilesToUpload.errorString())); QVERIFY2(dirForFilesToDownload.isValid(), qPrintable(dirForFilesToDownload.errorString())); QVERIFY2(dir2ForFilesToDownload.isValid(), qPrintable(dirForFilesToDownload.errorString())); - static const auto getRemoteFilePath = [](const QString &localFileName) { - return QString("/tmp/").append(localFileName).append(".upload"); - }; - FilesToTransfer filesToUpload; - std::srand(QDateTime::currentDateTime().toSecsSinceEpoch()); - for (int i = 0; i < 100; ++i) { - const QString fileName = "sftptestfile" + QString::number(i + 1); - QFile file(dirForFilesToUpload.path() + '/' + fileName); - QVERIFY2(file.open(QIODevice::WriteOnly), qPrintable(file.errorString())); - int content[1024 / sizeof(int)]; - for (size_t j = 0; j < sizeof content / sizeof content[0]; ++j) - content[j] = QRandomGenerator::global()->generate(); - file.write(reinterpret_cast<char *>(content), sizeof content); - file.close(); - QVERIFY2(file.error() == QFile::NoError, qPrintable(file.errorString())); - filesToUpload << FileToTransfer(file.fileName(), getRemoteFilePath(fileName)); - } const QString bigFileName("sftpbigfile"); QFile bigFile(dirForFilesToUpload.path() + '/' + bigFileName); QVERIFY2(bigFile.open(QIODevice::WriteOnly), qPrintable(bigFile.errorString())); @@ -201,25 +183,6 @@ void tst_Ssh::sftp() } bigFile.close(); QVERIFY2(bigFile.error() == QFile::NoError, qPrintable(bigFile.errorString())); - filesToUpload << FileToTransfer(bigFile.fileName(), getRemoteFilePath(bigFileName)); - - const SftpTransferPtr upload = connection.createUpload(filesToUpload); - QString jobError; - QEventLoop loop; - connect(upload.get(), &SftpTransfer::done, [&jobError, &loop](const QString &error) { - jobError = error; - loop.quit(); - }); - QTimer timer; - QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); - timer.setSingleShot(true); - timer.setInterval(30 * 1000); - timer.start(); - upload->start(); - loop.exec(); - QVERIFY(timer.isActive()); - timer.stop(); - QVERIFY2(jobError.isEmpty(), qPrintable(jobError)); } void tst_Ssh::cleanupTestCase() |