changed the way to get QSsh::SshConnection, now all resources are cleaned up after use, but the disconnectFromHost function becomes useless
This commit is contained in:
parent
fe7c66cf1d
commit
c319c3f520
2 changed files with 12 additions and 12 deletions
|
@ -38,7 +38,7 @@ ErrorCode ServerController::runScript(const ServerCredentials &credentials, QStr
|
||||||
const std::function<void(const QString &, QSharedPointer<SshRemoteProcess>)> &cbReadStdOut,
|
const std::function<void(const QString &, QSharedPointer<SshRemoteProcess>)> &cbReadStdOut,
|
||||||
const std::function<void(const QString &, QSharedPointer<SshRemoteProcess>)> &cbReadStdErr)
|
const std::function<void(const QString &, QSharedPointer<SshRemoteProcess>)> &cbReadStdErr)
|
||||||
{
|
{
|
||||||
SshConnection *client = connectToHost(sshParams(credentials));
|
QSharedPointer<SshConnection> client = connectToHost(sshParams(credentials));
|
||||||
if (client->state() == SshConnection::State::Connecting) {
|
if (client->state() == SshConnection::State::Connecting) {
|
||||||
qDebug() << "ServerController::runScript aborted, connectToHost in progress";
|
qDebug() << "ServerController::runScript aborted, connectToHost in progress";
|
||||||
return ErrorCode::SshTimeoutError;
|
return ErrorCode::SshTimeoutError;
|
||||||
|
@ -229,7 +229,7 @@ QByteArray ServerController::getTextFileFromContainer(DockerContainer container,
|
||||||
|
|
||||||
qDebug().noquote() << "Copy file from container\n" << script;
|
qDebug().noquote() << "Copy file from container\n" << script;
|
||||||
|
|
||||||
SshConnection *client = connectToHost(sshParams(credentials));
|
QSharedPointer<SshConnection> client = connectToHost(sshParams(credentials));
|
||||||
if (client->state() != SshConnection::State::Connected) {
|
if (client->state() != SshConnection::State::Connected) {
|
||||||
if (errorCode) *errorCode = fromSshConnectionErrorCode(client->errorState());
|
if (errorCode) *errorCode = fromSshConnectionErrorCode(client->errorState());
|
||||||
return {};
|
return {};
|
||||||
|
@ -288,7 +288,7 @@ ErrorCode ServerController::checkOpenVpnServer(DockerContainer container, const
|
||||||
ErrorCode ServerController::uploadFileToHost(const ServerCredentials &credentials, const QByteArray &data, const QString &remotePath,
|
ErrorCode ServerController::uploadFileToHost(const ServerCredentials &credentials, const QByteArray &data, const QString &remotePath,
|
||||||
QSsh::SftpOverwriteMode overwriteMode)
|
QSsh::SftpOverwriteMode overwriteMode)
|
||||||
{
|
{
|
||||||
SshConnection *client = connectToHost(sshParams(credentials));
|
QSharedPointer<SshConnection> client = connectToHost(sshParams(credentials));
|
||||||
if (client->state() != SshConnection::State::Connected) {
|
if (client->state() != SshConnection::State::Connected) {
|
||||||
return fromSshConnectionErrorCode(client->errorState());
|
return fromSshConnectionErrorCode(client->errorState());
|
||||||
}
|
}
|
||||||
|
@ -780,23 +780,23 @@ QString ServerController::checkSshConnection(const ServerCredentials &credential
|
||||||
return stdOut;
|
return stdOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
SshConnection *ServerController::connectToHost(const SshConnectionParameters &sshParams)
|
QSharedPointer<SshConnection> ServerController::connectToHost(const SshConnectionParameters &sshParams)
|
||||||
{
|
{
|
||||||
SshConnection *client = acquireConnection(sshParams);
|
QSharedPointer<SshConnection> client(new SshConnection(sshParams));
|
||||||
if (!client) return nullptr;
|
if (!client.get()) return nullptr;
|
||||||
|
|
||||||
QEventLoop waitssh;
|
QEventLoop waitssh;
|
||||||
QObject::connect(client, &SshConnection::connected, &waitssh, [&]() {
|
QObject::connect(client.get(), &SshConnection::connected, &waitssh, [&]() {
|
||||||
qDebug() << "Server connected by ssh";
|
qDebug() << "Server connected by ssh";
|
||||||
waitssh.quit();
|
waitssh.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(client, &SshConnection::disconnected, &waitssh, [&]() {
|
QObject::connect(client.get(), &SshConnection::disconnected, &waitssh, [&]() {
|
||||||
qDebug() << "Server disconnected by ssh";
|
qDebug() << "Server disconnected by ssh";
|
||||||
waitssh.quit();
|
waitssh.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(client, &SshConnection::error, &waitssh, [&](QSsh::SshError error) {
|
QObject::connect(client.get(), &SshConnection::error, &waitssh, [&](QSsh::SshError error) {
|
||||||
qCritical() << "Ssh error:" << error << client->errorString();
|
qCritical() << "Ssh error:" << error << client->errorString();
|
||||||
waitssh.quit();
|
waitssh.quit();
|
||||||
});
|
});
|
||||||
|
@ -841,8 +841,8 @@ void ServerController::setCancelInstallation(const bool cancel)
|
||||||
|
|
||||||
void ServerController::disconnectFromHost(const ServerCredentials &credentials)
|
void ServerController::disconnectFromHost(const ServerCredentials &credentials)
|
||||||
{
|
{
|
||||||
SshConnection *client = acquireConnection(sshParams(credentials));
|
// SshConnection *client = acquireConnection(sshParams(credentials));
|
||||||
if (client) client->disconnectFromHost();
|
// if (client) client->disconnectFromHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorCode ServerController::setupServerFirewall(const ServerCredentials &credentials)
|
ErrorCode ServerController::setupServerFirewall(const ServerCredentials &credentials)
|
||||||
|
|
|
@ -72,7 +72,7 @@ public:
|
||||||
Vars genVarsForScript(const ServerCredentials &credentials, DockerContainer container = DockerContainer::None, const QJsonObject &config = QJsonObject());
|
Vars genVarsForScript(const ServerCredentials &credentials, DockerContainer container = DockerContainer::None, const QJsonObject &config = QJsonObject());
|
||||||
|
|
||||||
QString checkSshConnection(const ServerCredentials &credentials, ErrorCode *errorCode = nullptr);
|
QString checkSshConnection(const ServerCredentials &credentials, ErrorCode *errorCode = nullptr);
|
||||||
QSsh::SshConnection *connectToHost(const QSsh::SshConnectionParameters &sshParams);
|
QSharedPointer<QSsh::SshConnection> connectToHost(const QSsh::SshConnectionParameters &sshParams);
|
||||||
|
|
||||||
void setCancelInstallation(const bool cancel);
|
void setCancelInstallation(const bool cancel);
|
||||||
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, QMap<DockerContainer, QJsonObject> &installedContainers);
|
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, QMap<DockerContainer, QJsonObject> &installedContainers);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue