Try to recover from corrupt metadata cache

This commit is contained in:
Torsten Grote 2024-02-06 16:55:08 -03:00 committed by Chirayu Desai
parent 6428399bed
commit 81fae1a240
2 changed files with 7 additions and 2 deletions

View file

@ -46,8 +46,12 @@ internal class MetadataManager(
field = try {
getMetadataFromCache() ?: throw IOException()
} catch (e: IOException) {
// If this happens, it is hard to recover from this. Let's hope it never does.
throw AssertionError("Error reading metadata from cache", e)
// This can happen if the storage location ran out of space
// or the app process got killed while writing the file.
// It is hard to recover from this, so we try as best as we can here:
Log.e(TAG, "ERROR getting metadata cache, creating new file ", e)
// This should cause requiresInit() return true
uninitializedMetadata.copy(version = (-1).toByte())
}
mLastBackupTime.postValue(field.time)
}

View file

@ -231,6 +231,7 @@ internal class BackupCoordinator(
): Int {
state.cancelReason = UNKNOWN_ERROR
if (metadataManager.requiresInit) {
Log.w(TAG, "Metadata requires re-init!")
// start a new restore set to upgrade from legacy format
// by starting a clean backup with all files using the new version
try {