summaryrefslogtreecommitdiff
path: root/src/libs/ssh
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2022-02-18 12:31:19 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2022-02-21 16:17:31 +0000
commit098e3794db16dc6da1dc2706c498e83968bcfe4c (patch)
treef29ba6e9adb8496546efeac0ae1187ef45d2d614 /src/libs/ssh
parent6360cffc80a4a309f39c1756834a9b76fd4bb9a9 (diff)
downloadqt-creator-098e3794db16dc6da1dc2706c498e83968bcfe4c.tar.gz
Get rid of SshProcess (one process class less)
Introduce static SshRemoteProcess::setupSshEnvironment() method instead. Change-Id: I9a49bc68bd96ddf0f58234d28b92a721f7d4bb56 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/libs/ssh')
-rw-r--r--src/libs/ssh/CMakeLists.txt1
-rw-r--r--src/libs/ssh/sftpsession.cpp5
-rw-r--r--src/libs/ssh/sftptransfer.cpp5
-rw-r--r--src/libs/ssh/ssh.qbs2
-rw-r--r--src/libs/ssh/sshconnection.cpp8
-rw-r--r--src/libs/ssh/sshprocess.cpp50
-rw-r--r--src/libs/ssh/sshprocess.h40
-rw-r--r--src/libs/ssh/sshremoteprocess.cpp31
-rw-r--r--src/libs/ssh/sshremoteprocess.h7
9 files changed, 42 insertions, 107 deletions
diff --git a/src/libs/ssh/CMakeLists.txt b/src/libs/ssh/CMakeLists.txt
index 6f5d1cb764..290afe5acd 100644
--- a/src/libs/ssh/CMakeLists.txt
+++ b/src/libs/ssh/CMakeLists.txt
@@ -11,7 +11,6 @@ add_qtc_library(QtcSsh
sshconnectionmanager.cpp sshconnectionmanager.h
sshkeycreationdialog.cpp sshkeycreationdialog.h sshkeycreationdialog.ui
sshlogging.cpp sshlogging_p.h
- sshprocess.cpp sshprocess.h
sshconnection.cpp sshconnection.h
sshconnectionmanager.cpp sshconnectionmanager.h
sshkeycreationdialog.cpp sshkeycreationdialog.h sshkeycreationdialog.ui
diff --git a/src/libs/ssh/sftpsession.cpp b/src/libs/ssh/sftpsession.cpp
index 6fbe26fb3c..2b5535e129 100644
--- a/src/libs/ssh/sftpsession.cpp
+++ b/src/libs/ssh/sftpsession.cpp
@@ -26,7 +26,7 @@
#include "sftpsession.h"
#include "sshlogging_p.h"
-#include "sshprocess.h"
+#include "sshremoteprocess.h"
#include "sshsettings.h"
#include <utils/fileutils.h>
@@ -58,7 +58,7 @@ struct Command
struct SftpSession::SftpSessionPrivate
{
- SshProcess sftpProc;
+ QtcProcess sftpProc;
QStringList connectionArgs;
QByteArray output;
QQueue<Command> pendingCommands;
@@ -111,6 +111,7 @@ static QByteArray prompt() { return "sftp> "; }
SftpSession::SftpSession(const QStringList &connectionArgs) : d(new SftpSessionPrivate)
{
+ SshRemoteProcess::setupSshEnvironment(&d->sftpProc);
d->sftpProc.setProcessMode(ProcessMode::Writer);
d->connectionArgs = connectionArgs;
connect(&d->sftpProc, &QtcProcess::started, [this] {
diff --git a/src/libs/ssh/sftptransfer.cpp b/src/libs/ssh/sftptransfer.cpp
index 26d4306f5c..3b2acf784c 100644
--- a/src/libs/ssh/sftptransfer.cpp
+++ b/src/libs/ssh/sftptransfer.cpp
@@ -26,7 +26,7 @@
#include "sftptransfer.h"
#include "sshlogging_p.h"
-#include "sshprocess.h"
+#include "sshremoteprocess.h"
#include "sshsettings.h"
#include <QDir>
@@ -44,7 +44,7 @@ namespace QSsh {
struct SftpTransfer::SftpTransferPrivate
{
- SshProcess sftpProc;
+ QtcProcess sftpProc;
FilesToTransfer files;
Internal::FileTransferType transferType;
FileTransferErrorHandling errorHandlingMode;
@@ -109,6 +109,7 @@ SftpTransfer::SftpTransfer(const FilesToTransfer &files, Internal::FileTransferT
const QStringList &connectionArgs)
: d(new SftpTransferPrivate)
{
+ SshRemoteProcess::setupSshEnvironment(&d->sftpProc);
d->files = files;
d->transferType = type;
d->errorHandlingMode = errorHandlingMode;
diff --git a/src/libs/ssh/ssh.qbs b/src/libs/ssh/ssh.qbs
index 36c69c7ee7..0b940452c3 100644
--- a/src/libs/ssh/ssh.qbs
+++ b/src/libs/ssh/ssh.qbs
@@ -29,8 +29,6 @@ Project {
"sshkeycreationdialog.ui",
"sshlogging.cpp",
"sshlogging_p.h",
- "sshprocess.cpp",
- "sshprocess.h",
"sshremoteprocess.cpp",
"sshremoteprocess.h",
"sshremoteprocessrunner.cpp",
diff --git a/src/libs/ssh/sshconnection.cpp b/src/libs/ssh/sshconnection.cpp
index 8eebad4e2b..4e695cbbfc 100644
--- a/src/libs/ssh/sshconnection.cpp
+++ b/src/libs/ssh/sshconnection.cpp
@@ -28,7 +28,6 @@
#include "sftpsession.h"
#include "sftptransfer.h"
#include "sshlogging_p.h"
-#include "sshprocess.h"
#include "sshremoteprocess.h"
#include "sshsettings.h"
@@ -129,7 +128,10 @@ bool operator!=(const SshConnectionParameters &p1, const SshConnectionParameters
struct SshConnection::SshConnectionPrivate
{
SshConnectionPrivate(const SshConnectionParameters &sshParameters)
- : connParams(sshParameters) {}
+ : connParams(sshParameters)
+ {
+ SshRemoteProcess::setupSshEnvironment(&masterProcess);
+ }
QString fullProcessError()
{
@@ -166,7 +168,7 @@ struct SshConnection::SshConnectionPrivate
const SshConnectionParameters connParams;
SshConnectionInfo connInfo;
- SshProcess masterProcess;
+ QtcProcess masterProcess;
QString errorString;
std::unique_ptr<QTemporaryDir> masterSocketDir;
State state = Unconnected;
diff --git a/src/libs/ssh/sshprocess.cpp b/src/libs/ssh/sshprocess.cpp
deleted file mode 100644
index d3063dfcb3..0000000000
--- a/src/libs/ssh/sshprocess.cpp
+++ /dev/null
@@ -1,50 +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 "sshprocess.h"
-
-#include "sshsettings.h"
-
-#include <utils/environment.h>
-
-namespace QSsh {
-
-SshProcess::SshProcess()
-{
- Utils::Environment env = Utils::Environment::systemEnvironment();
- if (SshSettings::askpassFilePath().exists()) {
- env.set("SSH_ASKPASS", SshSettings::askpassFilePath().toUserOutput());
-
- // OpenSSH only uses the askpass program if DISPLAY is set, regardless of the platform.
- if (!env.hasKey("DISPLAY"))
- env.set("DISPLAY", ":0");
- }
- setEnvironment(env);
-
- // Otherwise, ssh will ignore SSH_ASKPASS and read from /dev/tty directly.
- setDisableUnixTerminal();
-}
-
-} // namespace QSsh
diff --git a/src/libs/ssh/sshprocess.h b/src/libs/ssh/sshprocess.h
deleted file mode 100644
index afde29c538..0000000000
--- a/src/libs/ssh/sshprocess.h
+++ /dev/null
@@ -1,40 +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 "ssh_global.h"
-
-#include <utils/qtcprocess.h>
-
-namespace QSsh {
-
-class QSSH_EXPORT SshProcess : public Utils::QtcProcess
-{
-public:
- SshProcess();
-};
-
-} // namespace QSsh
diff --git a/src/libs/ssh/sshremoteprocess.cpp b/src/libs/ssh/sshremoteprocess.cpp
index a3c2a11481..13b40ff72e 100644
--- a/src/libs/ssh/sshremoteprocess.cpp
+++ b/src/libs/ssh/sshremoteprocess.cpp
@@ -46,12 +46,14 @@
*/
using namespace QSsh::Internal;
+using namespace Utils;
namespace QSsh {
SshRemoteProcess::SshRemoteProcess(const QString &command, const QStringList &connectionArgs)
- : SshProcess()
+ : QtcProcess()
{
+ setupSshEnvironment(this);
m_remoteCommand = command;
m_connectionArgs = connectionArgs;
@@ -70,9 +72,9 @@ SshRemoteProcess::SshRemoteProcess(const QString &command, const QStringList &co
void SshRemoteProcess::start()
{
QTC_ASSERT(!isRunning(), return);
- const Utils::CommandLine cmd = fullLocalCommandLine();
+ const CommandLine cmd = fullLocalCommandLine();
if (!m_displayName.isEmpty()) {
- Utils::Environment env = environment();
+ Environment env = environment();
env.set("DISPLAY", m_displayName);
setEnvironment(env);
}
@@ -86,9 +88,9 @@ void SshRemoteProcess::requestX11Forwarding(const QString &displayName)
m_displayName = displayName;
}
-Utils::CommandLine SshRemoteProcess::fullLocalCommandLine(bool inTerminal) const
+CommandLine SshRemoteProcess::fullLocalCommandLine(bool inTerminal) const
{
- Utils::CommandLine cmd{SshSettings::sshFilePath()};
+ CommandLine cmd {SshSettings::sshFilePath()};
if (!m_displayName.isEmpty())
cmd.addArg("-X");
@@ -104,4 +106,23 @@ Utils::CommandLine SshRemoteProcess::fullLocalCommandLine(bool inTerminal) const
return cmd;
}
+bool SshRemoteProcess::setupSshEnvironment(QtcProcess *process)
+{
+ Environment env = process->hasEnvironment() ? process->environment()
+ : Environment::systemEnvironment();
+ const bool hasDisplay = env.hasKey("DISPLAY") && (env.value("DISPLAY") != QString(":0"));
+ if (SshSettings::askpassFilePath().exists()) {
+ env.set("SSH_ASKPASS", SshSettings::askpassFilePath().toUserOutput());
+
+ // OpenSSH only uses the askpass program if DISPLAY is set, regardless of the platform.
+ if (!env.hasKey("DISPLAY"))
+ env.set("DISPLAY", ":0");
+ }
+ process->setEnvironment(env);
+
+ // Otherwise, ssh will ignore SSH_ASKPASS and read from /dev/tty directly.
+ process->setDisableUnixTerminal();
+ return hasDisplay;
+}
+
} // namespace QSsh
diff --git a/src/libs/ssh/sshremoteprocess.h b/src/libs/ssh/sshremoteprocess.h
index c4a28680b2..5fbe2da930 100644
--- a/src/libs/ssh/sshremoteprocess.h
+++ b/src/libs/ssh/sshremoteprocess.h
@@ -26,13 +26,14 @@
#pragma once
#include "ssh_global.h"
-#include "sshprocess.h"
+
+#include <utils/qtcprocess.h>
namespace Utils { class CommandLine; }
namespace QSsh {
-class QSSH_EXPORT SshRemoteProcess : public SshProcess
+class QSSH_EXPORT SshRemoteProcess : public Utils::QtcProcess
{
Q_OBJECT
@@ -44,6 +45,8 @@ public:
Utils::CommandLine fullLocalCommandLine(bool inTerminal = false) const;
+ static bool setupSshEnvironment(Utils::QtcProcess *process);
+
signals:
void done(const QString &error);