fix concurrent co mofification

This commit is contained in:
Valere 2020-02-02 15:28:00 +01:00
parent b158729b53
commit b182a63ea1

View File

@ -319,10 +319,11 @@ internal class DeviceListManager @Inject constructor(private val cryptoStore: IM
for (userId in filteredUsers) { for (userId in filteredUsers) {
// al devices = // al devices =
val models = response.deviceKeys?.get(userId)?.mapValues { entry -> CryptoInfoMapper.map(entry.value) } val models = response.deviceKeys?.get(userId)?.mapValues { entry -> CryptoInfoMapper.map(entry.value) }
?.toMutableMap()
Timber.v("## doKeyDownloadForUsers() : Got keys for $userId : $models") Timber.v("## doKeyDownloadForUsers() : Got keys for $userId : $models")
if (!models.isNullOrEmpty()) { if (!models.isNullOrEmpty()) {
val workingCopy = models.toMutableMap()
for ((deviceId, deviceInfo) in models) { for ((deviceId, deviceInfo) in models) {
// Get the potential previously store device keys for this device // Get the potential previously store device keys for this device
val previouslyStoredDeviceKeys = cryptoStore.getUserDevice(userId, deviceId) val previouslyStoredDeviceKeys = cryptoStore.getUserDevice(userId, deviceId)
@ -335,21 +336,21 @@ internal class DeviceListManager @Inject constructor(private val cryptoStore: IM
// Validate received keys // Validate received keys
if (!validateDeviceKeys(deviceInfo, userId, deviceId, previouslyStoredDeviceKeys)) { if (!validateDeviceKeys(deviceInfo, userId, deviceId, previouslyStoredDeviceKeys)) {
// New device keys are not valid. Do not store them // New device keys are not valid. Do not store them
models.remove(deviceId) workingCopy.remove(deviceId)
if (null != previouslyStoredDeviceKeys) { if (null != previouslyStoredDeviceKeys) {
// But keep old validated ones if any // But keep old validated ones if any
models[deviceId] = previouslyStoredDeviceKeys workingCopy[deviceId] = previouslyStoredDeviceKeys
} }
} else if (null != previouslyStoredDeviceKeys) { } else if (null != previouslyStoredDeviceKeys) {
// The verified status is not sync'ed with hs. // The verified status is not sync'ed with hs.
// This is a client side information, valid only for this client. // This is a client side information, valid only for this client.
// So, transfer its previous value // So, transfer its previous value
models[deviceId]!!.trustLevel = previouslyStoredDeviceKeys.trustLevel workingCopy[deviceId]!!.trustLevel = previouslyStoredDeviceKeys.trustLevel
} }
} }
// Update the store // Update the store
// Note that devices which aren't in the response will be removed from the stores // Note that devices which aren't in the response will be removed from the stores
cryptoStore.storeUserDevices(userId, models) cryptoStore.storeUserDevices(userId, workingCopy)
} }
// Handle cross signing keys update // Handle cross signing keys update