From 81fae1a24080c0b9a75fe2cb7953da72ab5f5117 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 6 Feb 2024 16:55:08 -0300 Subject: [PATCH] Try to recover from corrupt metadata cache --- .../com/stevesoltys/seedvault/metadata/MetadataManager.kt | 8 ++++++-- .../seedvault/transport/backup/BackupCoordinator.kt | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/metadata/MetadataManager.kt b/app/src/main/java/com/stevesoltys/seedvault/metadata/MetadataManager.kt index 1dfbab1d..0dc2663f 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/metadata/MetadataManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/metadata/MetadataManager.kt @@ -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) } diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt index 7025501f..c6f9e1c6 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt @@ -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 {