fix(cli): warn when FileStores delete() fails

Delete() returning false on a still-existing file meant we silently lost
scratch state for MLS group / key-package / message stores. Route the
four call sites through a `deleteOrWarn` helper that logs via the
KMP-safe quartz Log when the file refuses to disappear.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
davotoula
2026-04-24 11:10:39 +02:00
co-authored by Claude Opus 4.7
parent 33dacaa260
commit 20367af3db
@@ -23,8 +23,15 @@ package com.vitorpamplona.amethyst.cli.stores
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageBundleStore
import com.vitorpamplona.quartz.marmot.mls.group.MarmotMessageStore
import com.vitorpamplona.quartz.marmot.mls.group.MlsGroupStateStore
import com.vitorpamplona.quartz.utils.Log
import java.io.File
private fun File.deleteOrWarn(tag: String) {
if (!delete() && exists()) {
Log.w(tag) { "Failed to delete $absolutePath" }
}
}
/**
* Test-harness file stores. **Unencrypted** — the production interfaces
* document that implementations MUST encrypt at rest, but this CLI is a
@@ -53,8 +60,8 @@ class FileMlsGroupStateStore(
override suspend fun load(nostrGroupId: String): ByteArray? = stateFile(nostrGroupId).takeIf { it.exists() }?.readBytes()
override suspend fun delete(nostrGroupId: String) {
stateFile(nostrGroupId).delete()
retainedFile(nostrGroupId).delete()
stateFile(nostrGroupId).deleteOrWarn("FileMlsGroupStateStore")
retainedFile(nostrGroupId).deleteOrWarn("FileMlsGroupStateStore")
}
override suspend fun listGroups(): List<String> =
@@ -112,7 +119,7 @@ class FileKeyPackageBundleStore(
override suspend fun load(): ByteArray? = file.takeIf { it.exists() }?.readBytes()
override suspend fun delete() {
file.delete()
file.deleteOrWarn("FileKeyPackageBundleStore")
}
}
@@ -137,6 +144,6 @@ class FileMarmotMessageStore(
override suspend fun loadMessages(nostrGroupId: String): List<String> = file(nostrGroupId).takeIf { it.exists() }?.readLines()?.filter { it.isNotBlank() } ?: emptyList()
override suspend fun delete(nostrGroupId: String) {
file(nostrGroupId).delete()
file(nostrGroupId).deleteOrWarn("FileMarmotMessageStore")
}
}