android, desktop: check existence before deleting database (#5298)

This commit is contained in:
Stanislav Dmitrenko
2024-12-02 15:58:21 +00:00
committed by GitHub
parent 5a59fdd91c
commit f6b611aa30
2 changed files with 5 additions and 2 deletions
@@ -719,13 +719,16 @@ private fun deleteChatAlert(onConfirm: () -> Unit) {
}
private suspend fun deleteChat(m: ChatModel, progressIndicator: MutableState<Boolean>) {
if (!DatabaseUtils.hasAtLeastOneDatabase(dataDir.absolutePath)) {
return
}
progressIndicator.value = true
try {
deleteChatAsync(m)
operationEnded(m, progressIndicator) {
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.chat_database_deleted), generalGetString(MR.strings.restart_the_app_to_create_a_new_chat_profile))
}
} catch (e: Error) {
} catch (e: Throwable) {
operationEnded(m, progressIndicator) {
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.error_deleting_database), e.toString())
}
@@ -39,7 +39,7 @@ object DatabaseUtils {
}
}
private fun hasAtLeastOneDatabase(rootDir: String): Boolean =
fun hasAtLeastOneDatabase(rootDir: String): Boolean =
File(rootDir + File.separator + chatDatabaseFileName).exists() || File(rootDir + File.separator + agentDatabaseFileName).exists()
fun hasOnlyOneDatabase(rootDir: String): Boolean =