forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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
|
||||
|
@@ -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] {
|
||||
|
@@ -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;
|
||||
|
@@ -29,8 +29,6 @@ Project {
|
||||
"sshkeycreationdialog.ui",
|
||||
"sshlogging.cpp",
|
||||
"sshlogging_p.h",
|
||||
"sshprocess.cpp",
|
||||
"sshprocess.h",
|
||||
"sshremoteprocess.cpp",
|
||||
"sshremoteprocess.h",
|
||||
"sshremoteprocessrunner.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;
|
||||
|
@@ -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
|
@@ -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
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -466,21 +466,7 @@ void LinuxDevice::runProcess(QtcProcess &process) const
|
||||
{
|
||||
QTC_ASSERT(!process.isRunning(), return);
|
||||
|
||||
Utils::Environment env = process.hasEnvironment() ? process.environment()
|
||||
: Utils::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();
|
||||
|
||||
const bool hasDisplay = SshRemoteProcess::setupSshEnvironment(&process);
|
||||
process.setCommand(d->fullLocalCommandLine(process.commandLine(), process.terminalMode(),
|
||||
hasDisplay));
|
||||
process.start();
|
||||
|
@@ -55,7 +55,7 @@ public:
|
||||
SshRemoteProcessPtr process;
|
||||
DeviceUsedPortsGatherer portsGatherer;
|
||||
SftpTransferPtr sftpTransfer;
|
||||
SshProcess rsyncProcess;
|
||||
Utils::QtcProcess rsyncProcess;
|
||||
State state = Inactive;
|
||||
bool sftpWorks = false;
|
||||
};
|
||||
@@ -67,6 +67,7 @@ using namespace Internal;
|
||||
GenericLinuxDeviceTester::GenericLinuxDeviceTester(QObject *parent)
|
||||
: DeviceTester(parent), d(new GenericLinuxDeviceTesterPrivate)
|
||||
{
|
||||
SshRemoteProcess::setupSshEnvironment(&d->rsyncProcess);
|
||||
}
|
||||
|
||||
GenericLinuxDeviceTester::~GenericLinuxDeviceTester()
|
||||
|
@@ -48,7 +48,8 @@ class RsyncDeployService : public AbstractRemoteLinuxDeployService
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RsyncDeployService(QObject *parent = nullptr) : AbstractRemoteLinuxDeployService(parent) {}
|
||||
RsyncDeployService(QObject *parent = nullptr) : AbstractRemoteLinuxDeployService(parent)
|
||||
{ SshRemoteProcess::setupSshEnvironment(&m_rsync); }
|
||||
|
||||
void setDeployableFiles(const QList<DeployableFile> &files) { m_deployableFiles = files; }
|
||||
void setIgnoreMissingFiles(bool ignore) { m_ignoreMissingFiles = ignore; }
|
||||
@@ -69,7 +70,7 @@ private:
|
||||
mutable QList<DeployableFile> m_deployableFiles;
|
||||
bool m_ignoreMissingFiles = false;
|
||||
QString m_flags;
|
||||
SshProcess m_rsync;
|
||||
QtcProcess m_rsync;
|
||||
SshRemoteProcessPtr m_mkdir;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user