Fix / protect against crash during migration

This commit is contained in:
Valere 2020-03-26 18:20:12 +01:00
parent 024c62515c
commit a995615f87
1 changed files with 35 additions and 29 deletions

View File

@ -102,6 +102,7 @@ internal object RealmCryptoStoreMigration : RealmMigration {
?.addRealmObjectField(DeviceInfoEntityFields.TRUST_LEVEL_ENTITY.`$`, trustLevelentityEntitySchema)
?.transform { obj ->
try {
val oldSerializedData = obj.getString("deviceInfoData")
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.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")
}