From a4b68af77802b176365f1d3648ecc5f46bda7e44 Mon Sep 17 00:00:00 2001 From: davotoula Date: Fri, 11 Sep 2026 14:48:05 +0200 Subject: [PATCH] fix(marmot): log ignored File.delete results in AndroidPushStateStore Sonar flagged both delete() calls for discarding the Boolean result. save() now warns when the temp file left behind by a failed rename cannot be removed, and clear() only deletes a file that exists and warns when the delete is refused. --- .../amethyst/model/marmot/AndroidPushStateStore.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/marmot/AndroidPushStateStore.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/marmot/AndroidPushStateStore.kt index e5ca421806..80cae35d7a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/marmot/AndroidPushStateStore.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/marmot/AndroidPushStateStore.kt @@ -90,7 +90,9 @@ class AndroidPushStateStore( temp.writeText(state) if (!temp.renameTo(target)) { target.writeText(state) - temp.delete() + if (!temp.delete()) { + Log.w(TAG) { "could not remove temp push state file ${temp.name}" } + } } } catch (e: Exception) { Log.w(TAG, "could not persist push state for $nostrGroupId: ${e.message}", e) @@ -102,7 +104,10 @@ class AndroidPushStateStore( withContext(Dispatchers.IO) { mutex.withLock { try { - file(nostrGroupId)?.delete() + val target = file(nostrGroupId)?.takeIf { it.exists() } + if (target != null && !target.delete()) { + Log.w(TAG) { "could not delete push state for $nostrGroupId" } + } } catch (e: Exception) { Log.w(TAG, "could not clear push state for $nostrGroupId: ${e.message}", e) }