ProjectExplorer: Use SyncronizedValue instead

Protect sshParameters with SyncronizedValue instead of
manual QReadWrite lock.

Change-Id: Ib164eb34aa1b8167d00c02ce49fd5bfc9fba6c15
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-12-12 09:23:45 +01:00
parent 27ef041d28
commit b6ee23d218

View File

@@ -20,6 +20,7 @@
#include <utils/icon.h> #include <utils/icon.h>
#include <utils/portlist.h> #include <utils/portlist.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/synchronizedvalue.h>
#include <utils/url.h> #include <utils/url.h>
#include <QCoreApplication> #include <QCoreApplication>
@@ -139,8 +140,8 @@ public:
DeviceFileAccess *fileAccess = nullptr; DeviceFileAccess *fileAccess = nullptr;
int version = 0; // This is used by devices that have been added by the SDK. int version = 0; // This is used by devices that have been added by the SDK.
QReadWriteLock lock; // Currently used to protect sshParameters only Utils::SynchronizedValue<SshParameters> sshParameters;
SshParameters sshParameters;
PortList freePorts; PortList freePorts;
FilePath debugServerPath; FilePath debugServerPath;
FilePath debugDumperPath = Core::ICore::resourcePath("debugger/"); FilePath debugDumperPath = Core::ICore::resourcePath("debugger/");
@@ -489,24 +490,23 @@ void IDevice::fromMap(const Store &map)
d->id = newId(); d->id = newId();
d->origin = static_cast<Origin>(map.value(OriginKey, ManuallyAdded).toInt()); d->origin = static_cast<Origin>(map.value(OriginKey, ManuallyAdded).toInt());
QWriteLocker locker(&d->lock); d->sshParameters.write([&map](SshParameters &ssh) {
d->sshParameters.setHost(map.value(HostKey).toString()); ssh.setHost(map.value(HostKey).toString());
d->sshParameters.setPort(map.value(SshPortKey, 22).toInt()); ssh.setPort(map.value(SshPortKey, 22).toInt());
d->sshParameters.setUserName(map.value(UserNameKey).toString()); ssh.setUserName(map.value(UserNameKey).toString());
// Pre-4.9, the authentication enum used to have more values // Pre-4.9, the authentication enum used to have more values
const int storedAuthType = map.value(AuthKey, DefaultAuthType).toInt(); const int storedAuthType = map.value(AuthKey, DefaultAuthType).toInt();
const bool outdatedAuthType = storedAuthType const bool outdatedAuthType = storedAuthType > SshParameters::AuthenticationTypeSpecificKey;
> SshParameters::AuthenticationTypeSpecificKey; ssh.authenticationType = outdatedAuthType ? SshParameters::AuthenticationTypeAll
d->sshParameters.authenticationType = outdatedAuthType
? SshParameters::AuthenticationTypeAll
: static_cast<AuthType>(storedAuthType); : static_cast<AuthType>(storedAuthType);
d->sshParameters.privateKeyFile = ssh.privateKeyFile = FilePath::fromSettings(
FilePath::fromSettings(map.value(KeyFileKey, defaultPrivateKeyFilePath())); map.value(KeyFileKey, defaultPrivateKeyFilePath()));
d->sshParameters.timeout = map.value(TimeoutKey, DefaultTimeout).toInt(); ssh.timeout = map.value(TimeoutKey, DefaultTimeout).toInt();
d->sshParameters.hostKeyCheckingMode = static_cast<SshHostKeyCheckingMode> ssh.hostKeyCheckingMode = static_cast<SshHostKeyCheckingMode>(
(map.value(HostKeyCheckingKey, SshHostKeyCheckingNone).toInt()); map.value(HostKeyCheckingKey, SshHostKeyCheckingNone).toInt());
});
QString portsSpec = map.value(PortsSpecKey).toString(); QString portsSpec = map.value(PortsSpecKey).toString();
if (portsSpec.isEmpty()) if (portsSpec.isEmpty())
@@ -537,15 +537,17 @@ Store IDevice::toMap() const
map.insert(IdKey, d->id.toSetting()); map.insert(IdKey, d->id.toSetting());
map.insert(OriginKey, d->origin); map.insert(OriginKey, d->origin);
QReadLocker locker(&d->lock);
map.insert(MachineTypeKey, d->machineType); map.insert(MachineTypeKey, d->machineType);
map.insert(HostKey, d->sshParameters.host());
map.insert(SshPortKey, d->sshParameters.port()); d->sshParameters.read([&map](const auto &ssh) {
map.insert(UserNameKey, d->sshParameters.userName()); map.insert(HostKey, ssh.host());
map.insert(AuthKey, d->sshParameters.authenticationType); map.insert(SshPortKey, ssh.port());
map.insert(KeyFileKey, d->sshParameters.privateKeyFile.toSettings()); map.insert(UserNameKey, ssh.userName());
map.insert(TimeoutKey, d->sshParameters.timeout); map.insert(AuthKey, ssh.authenticationType);
map.insert(HostKeyCheckingKey, d->sshParameters.hostKeyCheckingMode); map.insert(KeyFileKey, ssh.privateKeyFile.toSettings());
map.insert(TimeoutKey, ssh.timeout);
map.insert(HostKeyCheckingKey, ssh.hostKeyCheckingMode);
});
map.insert(PortsSpecKey, d->freePorts.toString()); map.insert(PortsSpecKey, d->freePorts.toString());
map.insert(VersionKey, d->version); map.insert(VersionKey, d->version);
@@ -590,22 +592,19 @@ QString IDevice::deviceStateToString() const
SshParameters IDevice::sshParameters() const SshParameters IDevice::sshParameters() const
{ {
QReadLocker locker(&d->lock); return *d->sshParameters.readLocked();
return d->sshParameters;
} }
void IDevice::setSshParameters(const SshParameters &sshParameters) void IDevice::setSshParameters(const SshParameters &sshParameters)
{ {
QWriteLocker locker(&d->lock); *d->sshParameters.writeLocked() = sshParameters;
d->sshParameters = sshParameters;
} }
QUrl IDevice::toolControlChannel(const ControlChannelHint &) const QUrl IDevice::toolControlChannel(const ControlChannelHint &) const
{ {
QUrl url; QUrl url;
url.setScheme(urlTcpScheme()); url.setScheme(urlTcpScheme());
QReadLocker locker(&d->lock); url.setHost(d->sshParameters.readLocked()->host());
url.setHost(d->sshParameters.host());
return url; return url;
} }