From 7f91090dcd692ec5bd2837b9a080d0edd81da7e8 Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Sat, 1 Jun 2024 17:30:53 +0200 Subject: [PATCH] Added logging for database corruption --- .../data/db/DatabaseOpenHelperFactory.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/data/src/main/java/org/cryptomator/data/db/DatabaseOpenHelperFactory.kt b/data/src/main/java/org/cryptomator/data/db/DatabaseOpenHelperFactory.kt index 88e7406ec..a370d236c 100644 --- a/data/src/main/java/org/cryptomator/data/db/DatabaseOpenHelperFactory.kt +++ b/data/src/main/java/org/cryptomator/data/db/DatabaseOpenHelperFactory.kt @@ -78,13 +78,33 @@ private class PatchedCallback( } override fun onCorruption(db: SupportSQLiteDatabase) = useFinally({ + LOG.e(Exception(), "Called onCorruption for \"${db.path}\"") // delegateCallback.onCorruption(db) // }, finallyBlock = { invalidationCallback.invoke() + + logCorruptedDbState(db) }) + private fun logCorruptedDbState(db: SupportSQLiteDatabase) { + val state = db.path?.let { path -> + if (path == ":memory:") null else path + }.runCatching { + this?.let { path -> (File(path).exists()) } + }.map { + when (it) { + null -> "In memory" + true -> "Exists" + false -> "Deleted" + } + }.onFailure { verificationFailure -> + LOG.e(verificationFailure, "Couldn't verify state of database \"${db.path}\"") + }.getOrDefault("Unknown (see above)") + LOG.e(Exception(), "State of \"${db.path}\": $state") + } + override fun onOpen(db: SupportSQLiteDatabase) { // delegateCallback.onOpen(db)