diff --git a/apps/ios/SimpleXChat/FileUtils.swift b/apps/ios/SimpleXChat/FileUtils.swift index 0c1852b09c..69bf305147 100644 --- a/apps/ios/SimpleXChat/FileUtils.swift +++ b/apps/ios/SimpleXChat/FileUtils.swift @@ -50,6 +50,10 @@ private let CHAT_DB_BAK: String = "_chat.db.bak" private let AGENT_DB_BAK: String = "_agent.db.bak" +private let CHAT_DB_EXPORTED: String = "_chat.db.exported" + +private let AGENT_DB_EXPORTED: String = "_agent.db.exported" + // Spec: spec/database.md#getDocumentsDirectory public func getDocumentsDirectory() -> URL { FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! @@ -113,6 +117,8 @@ public func deleteAppDatabaseAndFiles() { } try? fm.removeItem(atPath: dbPath + CHAT_DB_BAK) try? fm.removeItem(atPath: dbPath + AGENT_DB_BAK) + try? fm.removeItem(atPath: dbPath + CHAT_DB_EXPORTED) + try? fm.removeItem(atPath: dbPath + AGENT_DB_EXPORTED) try? fm.removeItem(at: getTempFilesDirectory()) try? fm.removeItem(at: getMigrationTempFilesDirectory()) try? fm.createDirectory(at: getTempFilesDirectory(), withIntermediateDirectories: true) @@ -210,6 +216,8 @@ public func removeLegacyDatabaseAndFiles() -> Bool { let r2 = nil != (try? fm.removeItem(atPath: dbPath.path + CHAT_DB)) try? fm.removeItem(atPath: dbPath.path + AGENT_DB_BAK) try? fm.removeItem(atPath: dbPath.path + CHAT_DB_BAK) + try? fm.removeItem(atPath: dbPath.path + AGENT_DB_EXPORTED) + try? fm.removeItem(atPath: dbPath.path + CHAT_DB_EXPORTED) try? fm.removeItem(at: appFiles) return r1 && r2 } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/database/DatabaseView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/database/DatabaseView.kt index 241826ac41..c6bbb93294 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/database/DatabaseView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/database/DatabaseView.kt @@ -556,12 +556,16 @@ suspend fun deleteChatAsync(m: ChatModel) { fun deleteChatDatabaseFilesAndState() { val chat = File(dataDir, chatDatabaseFileName) val chatBak = File(dataDir, "$chatDatabaseFileName.bak") + val chatExported = File(dataDir, "$chatDatabaseFileName.exported") val agent = File(dataDir, agentDatabaseFileName) val agentBak = File(dataDir, "$agentDatabaseFileName.bak") + val agentExported = File(dataDir, "$agentDatabaseFileName.exported") chat.delete() chatBak.delete() + chatExported.delete() agent.delete() agentBak.delete() + agentExported.delete() filesDir.deleteRecursively() filesDir.mkdir() remoteHostsDir.deleteRecursively() diff --git a/src/Simplex/Chat/Archive.hs b/src/Simplex/Chat/Archive.hs index b54c23959b..cd2d04e78d 100644 --- a/src/Simplex/Chat/Archive.hs +++ b/src/Simplex/Chat/Archive.hs @@ -124,11 +124,13 @@ deleteStorage = do fs <- lift storageFiles liftIO $ closeDBStore `withStores` fs remove `withDBs` fs + removeExported `withDBs` fs mapM_ removeDir $ filesPath fs mapM_ removeDir $ assetsPath fs mapM_ removeDir =<< chatReadVar tempDirectory where remove f = whenM (doesFileExist f) $ removeFile f + removeExported f = remove $ f <> ".exported" removeDir d = whenM (doesDirectoryExist d) $ removePathForcibly d data StorageFiles = StorageFiles diff --git a/tests/ChatTests/Direct.hs b/tests/ChatTests/Direct.hs index 6a85f6f463..72a72de794 100644 --- a/tests/ChatTests/Direct.hs +++ b/tests/ChatTests/Direct.hs @@ -1493,12 +1493,15 @@ testMaintenanceModeWithFiles ps = withXFTPServer $ do alice <## "chat stopped" alice ##> "/_db export {\"archivePath\": \"./tests/tmp/alice-chat.zip\"}" alice <## "ok" + let exportedDBs = [tmpPath ps <> "/alice_chat.db.exported", tmpPath ps <> "/alice_agent.db.exported"] + forM_ exportedDBs $ \f -> B.writeFile f "" alice ##> "/_db delete" alice <## "ok" -- cannot start chat after delete alice ##> "/_start" alice <## "error: chat store changed, please restart chat" doesDirectoryExist "./tests/tmp/alice_files" `shouldReturn` False + forM_ exportedDBs $ \f -> doesFileExist f `shouldReturn` False alice ##> "/_db import {\"archivePath\": \"./tests/tmp/alice-chat.zip\"}" alice <## "ok" B.readFile "./tests/tmp/alice_files/test.jpg" `shouldReturn` src