Fix / protect against crash during migration

This commit is contained in:
Valere 2020-03-26 18:20:12 +01:00
parent 024c62515c
commit a995615f87

View file

@ -102,6 +102,7 @@ internal object RealmCryptoStoreMigration : RealmMigration {
?.addRealmObjectField(DeviceInfoEntityFields.TRUST_LEVEL_ENTITY.`$`, trustLevelentityEntitySchema) ?.addRealmObjectField(DeviceInfoEntityFields.TRUST_LEVEL_ENTITY.`$`, trustLevelentityEntitySchema)
?.transform { obj -> ?.transform { obj ->
try {
val oldSerializedData = obj.getString("deviceInfoData") val oldSerializedData = obj.getString("deviceInfoData")
deserializeFromRealm<MXDeviceInfo>(oldSerializedData)?.let { oldDevice -> deserializeFromRealm<MXDeviceInfo>(oldSerializedData)?.let { oldDevice ->
@ -135,6 +136,11 @@ internal object RealmCryptoStoreMigration : RealmMigration {
obj.setString(DeviceInfoEntityFields.SIGNATURE_MAP_JSON, mapMigrationAdapter.toJson(oldDevice.signatures)) obj.setString(DeviceInfoEntityFields.SIGNATURE_MAP_JSON, mapMigrationAdapter.toJson(oldDevice.signatures))
obj.setString(DeviceInfoEntityFields.UNSIGNED_MAP_JSON, mapMigrationAdapter.toJson(oldDevice.unsigned)) obj.setString(DeviceInfoEntityFields.UNSIGNED_MAP_JSON, mapMigrationAdapter.toJson(oldDevice.unsigned))
} }
} catch (failure: Throwable) {
Timber.w(failure, "Crypto Data base migration error")
// an unfortunate refactor did modify that class, making deserialization failing
// so we just skip and ignore..
}
} }
?.removeField("deviceInfoData") ?.removeField("deviceInfoData")
} }