diff --git a/src/plugins/projectexplorer/devicesupport/sshparameters.cpp b/src/plugins/projectexplorer/devicesupport/sshparameters.cpp index 22055cf7946..1467f958b99 100644 --- a/src/plugins/projectexplorer/devicesupport/sshparameters.cpp +++ b/src/plugins/projectexplorer/devicesupport/sshparameters.cpp @@ -27,6 +27,12 @@ QString SshParameters::userAtHost() const if (!m_userName.isEmpty()) res = m_userName + '@'; res += m_host; + return res; +} + +QString SshParameters::userAtHostAndPort() const +{ + QString res = SshParameters::userAtHost(); if (m_port != 22) res += QString(":%1").arg(m_port); return res; @@ -142,6 +148,15 @@ const QString userAtHost() return userMidFix + getHostFromEnvironment(); } +const QString userAtHostAndPort() +{ + QString res = userAtHost(); + const int port = getPortFromEnvironment(); + if (port != 22) + res += QString(":%1").arg(port); + return res; +} + SshParameters getParameters() { SshParameters params; diff --git a/src/plugins/projectexplorer/devicesupport/sshparameters.h b/src/plugins/projectexplorer/devicesupport/sshparameters.h index 3ee483d5f3d..5a5f32da268 100644 --- a/src/plugins/projectexplorer/devicesupport/sshparameters.h +++ b/src/plugins/projectexplorer/devicesupport/sshparameters.h @@ -32,6 +32,7 @@ public: QString userName() const { return m_userName; } QString userAtHost() const; + QString userAtHostAndPort() const; void setHost(const QString &host) { m_host = host; } void setPort(int port) { m_port = port; } @@ -63,6 +64,7 @@ quint16 PROJECTEXPLORER_EXPORT getPortFromEnvironment(); const QString PROJECTEXPLORER_EXPORT getUserFromEnvironment(); const QString PROJECTEXPLORER_EXPORT getKeyFileFromEnvironment(); const PROJECTEXPLORER_EXPORT QString userAtHost(); +const PROJECTEXPLORER_EXPORT QString userAtHostAndPort(); SshParameters PROJECTEXPLORER_EXPORT getParameters(); bool PROJECTEXPLORER_EXPORT checkParameters(const SshParameters ¶ms); void PROJECTEXPLORER_EXPORT printSetupHelp(); diff --git a/src/plugins/remotelinux/filesystemaccess_test.cpp b/src/plugins/remotelinux/filesystemaccess_test.cpp index 2edb78fa7b3..f8afdd22423 100644 --- a/src/plugins/remotelinux/filesystemaccess_test.cpp +++ b/src/plugins/remotelinux/filesystemaccess_test.cpp @@ -33,7 +33,7 @@ static const char TEST_DIR[] = "/tmp/testdir"; static const FilePath baseFilePath() { - return FilePath::fromString("ssh://" + SshTest::userAtHost() + QString(TEST_DIR)); + return FilePath::fromString("ssh://" + SshTest::userAtHostAndPort() + QString(TEST_DIR)); } TestLinuxDeviceFactory::TestLinuxDeviceFactory() @@ -55,7 +55,7 @@ TestLinuxDeviceFactory::TestLinuxDeviceFactory() FilePath createFile(const QString &name) { FilePath testFilePath = baseFilePath() / name; - FilePath dummyFilePath = FilePath::fromString("ssh://" + SshTest::userAtHost() + "/dev/null"); + FilePath dummyFilePath = FilePath::fromString("ssh://" + SshTest::userAtHostAndPort() + "/dev/null"); dummyFilePath.copyFile(testFilePath); return testFilePath; } diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 3707f660052..1b4af90f912 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -843,13 +843,14 @@ public: << m_displaylessSshParameters.host()); cmd.addArg("/bin/sh"); - m_shell.reset(new LinuxDeviceShell(cmd, FilePath::fromString(QString("ssh://%1/").arg(parameters.userAtHost())))); + m_shell.reset(new LinuxDeviceShell(cmd, + FilePath::fromString(QString("ssh://%1/").arg(parameters.userAtHostAndPort())))); connect(m_shell.get(), &DeviceShell::done, this, [this] { m_shell.release()->deleteLater(); }); auto result = m_shell->start(); if (!result) { - qCWarning(linuxDeviceLog) << "Failed to start shell for:" << parameters.userAtHost() + qCWarning(linuxDeviceLog) << "Failed to start shell for:" << parameters.userAtHostAndPort() << ", " << result.error(); } return result.has_value(); @@ -1027,16 +1028,21 @@ QString LinuxDevice::userAtHost() const return sshParameters().userAtHost(); } +QString LinuxDevice::userAtHostAndPort() const +{ + return sshParameters().userAtHostAndPort(); +} + FilePath LinuxDevice::rootPath() const { - return FilePath::fromParts(u"ssh", userAtHost(), u"/"); + return FilePath::fromParts(u"ssh", userAtHostAndPort(), u"/"); } bool LinuxDevice::handlesFile(const FilePath &filePath) const { if (filePath.scheme() == u"device" && filePath.host() == id().toString()) return true; - if (filePath.scheme() == u"ssh" && filePath.host() == userAtHost()) + if (filePath.scheme() == u"ssh" && filePath.host() == userAtHostAndPort()) return true; return false; } diff --git a/src/plugins/remotelinux/linuxdevice.h b/src/plugins/remotelinux/linuxdevice.h index d0a06219e8e..40ce9c4860e 100644 --- a/src/plugins/remotelinux/linuxdevice.h +++ b/src/plugins/remotelinux/linuxdevice.h @@ -29,6 +29,7 @@ public: bool usableAsBuildDevice() const override; QString userAtHost() const; + QString userAtHostAndPort() const; Utils::FilePath rootPath() const override;