|
11 | 11 | #include <QStandardPaths> |
12 | 12 | #include <QThread> |
13 | 13 |
|
| 14 | +#include <QCoroProcess> |
| 15 | + |
14 | 16 | #include <KSharedConfig> |
15 | 17 |
|
16 | 18 | #include "settings.h" |
@@ -74,6 +76,10 @@ RemoteDevice::~RemoteDevice() |
74 | 76 | { |
75 | 77 | if (m_connection) { |
76 | 78 | disconnect(); |
| 79 | + QTimer::singleShot(0, this, [connection = m_connection.release()]() -> QCoro::Task<void> { |
| 80 | + co_await qCoro(connection).waitForFinished(); |
| 81 | + delete connection; |
| 82 | + }); |
77 | 83 | } |
78 | 84 | } |
79 | 85 |
|
@@ -122,34 +128,36 @@ bool RemoteDevice::isConnected() const |
122 | 128 |
|
123 | 129 | bool RemoteDevice::checkIfProgramExists(const QString& program) const |
124 | 130 | { |
| 131 | + Q_ASSERT(QThread::currentThread() != thread()); |
| 132 | + // this is only used to check if perf is installed and is run in a background thread |
125 | 133 | auto ssh = sshProcess({QStringLiteral("command"), program}); |
126 | 134 | ssh->start(); |
127 | 135 | ssh->waitForFinished(); |
128 | 136 | auto exitCode = ssh->exitCode(); |
129 | | - ssh->deleteLater(); |
130 | 137 | // 128 -> not found |
131 | 138 | // perf will return 1 and display the help message |
132 | 139 | return exitCode != 128; |
133 | 140 | } |
134 | 141 |
|
135 | | -bool RemoteDevice::checkIfDirectoryExists(const QString& directory) const |
| 142 | +QCoro::Task<bool> RemoteDevice::checkIfDirectoryExists(const QString& directory) const |
136 | 143 | { |
137 | | - auto ssh = sshProcess({QStringLiteral("test"), QStringLiteral("-d"), directory}); |
138 | | - ssh->start(); |
139 | | - ssh->waitForFinished(); |
140 | | - auto exitCode = ssh->exitCode(); |
141 | | - ssh->deleteLater(); |
142 | | - return exitCode == 0; |
| 144 | + auto _ssh = sshProcess({QStringLiteral("test"), QStringLiteral("-d"), directory}); |
| 145 | + auto ssh = qCoro(_ssh.get()); |
| 146 | + co_await ssh.start(); |
| 147 | + co_await ssh.waitForFinished(); |
| 148 | + auto exitCode = _ssh->exitCode(); |
| 149 | + co_return exitCode == 0; |
143 | 150 | } |
144 | 151 |
|
145 | | -bool RemoteDevice::checkIfFileExists(const QString& file) const |
| 152 | +QCoro::Task<bool> RemoteDevice::checkIfFileExists(const QString& file) const |
146 | 153 | { |
147 | | - auto ssh = sshProcess({QStringLiteral("test"), QStringLiteral("-f"), file}); |
148 | | - ssh->start(); |
149 | | - ssh->waitForFinished(); |
150 | | - auto exitCode = ssh->exitCode(); |
151 | | - ssh->deleteLater(); |
152 | | - return exitCode == 0; |
| 154 | + auto _ssh = sshProcess({QStringLiteral("test"), QStringLiteral("-f"), file}); |
| 155 | + |
| 156 | + auto ssh = qCoro(_ssh.get()); |
| 157 | + co_await ssh.start(); |
| 158 | + co_await ssh.waitForFinished(); |
| 159 | + auto exitCode = _ssh->exitCode(); |
| 160 | + co_return exitCode == 0; |
153 | 161 | } |
154 | 162 |
|
155 | 163 | QByteArray RemoteDevice::getProgramOutput(const QStringList& args) const |
|
0 commit comments