From a2ec12aa086b3f927d990720ab742f8fced29e02 Mon Sep 17 00:00:00 2001 From: talh4tr Date: Mon, 28 Sep 2026 16:12:37 +0300 Subject: [PATCH] =?UTF-8?q?Kasa=20meta=20dosyas=C4=B1n=C4=B1=20silmeden=20?= =?UTF-8?q?yenile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Meta yazılırken mevcut dosya, geçici dosya hedefe taşınmadan önce siliniyordu. Önce doğrudan replacement dene; desteklenmezse mevcut fallback yoluna geç. --- .../kotlin/dev/stade/security/FileVaultTest.kt | 18 ++++++++++++++++++ .../kotlin/dev/stade/security/FileVault.kt | 1 + 2 files changed, 19 insertions(+) diff --git a/composeApp/src/desktopTest/kotlin/dev/stade/security/FileVaultTest.kt b/composeApp/src/desktopTest/kotlin/dev/stade/security/FileVaultTest.kt index 530e78a..5cbb596 100644 --- a/composeApp/src/desktopTest/kotlin/dev/stade/security/FileVaultTest.kt +++ b/composeApp/src/desktopTest/kotlin/dev/stade/security/FileVaultTest.kt @@ -8,6 +8,24 @@ import kotlin.test.assertTrue class FileVaultTest { + @Test + fun rewritesVaultMetaWithoutLeavingTemporaryFile() { + val root = Files.createTempDirectory("stade-vault-test") + try { + val vault = FileVault(root.toFile()) + vault.setup("1234") + vault.setScrambleKeypadEnabled(true) + + assertFalse(root.resolve("stade.vault.tmp").toFile().exists()) + + val reopened = FileVault(root.toFile()) + assertTrue(reopened.unlock("1234") is UnlockOutcome.Success) + assertTrue(reopened.isScrambleKeypadEnabled()) + } finally { + root.toFile().deleteRecursively() + } + } + @Test fun flushAndCloseEncryptsThenRemovesPlaintextDatabase() { val root = Files.createTempDirectory("stade-vault-test") diff --git a/composeApp/src/jvmCommonMain/kotlin/dev/stade/security/FileVault.kt b/composeApp/src/jvmCommonMain/kotlin/dev/stade/security/FileVault.kt index 090d08a..a1a0ed4 100644 --- a/composeApp/src/jvmCommonMain/kotlin/dev/stade/security/FileVault.kt +++ b/composeApp/src/jvmCommonMain/kotlin/dev/stade/security/FileVault.kt @@ -492,6 +492,7 @@ class FileVault(private val rootDir: File) : Vault { buf.put(meta.duressVerifierCipher) val tmp = File(metaFile.parentFile, metaFile.name + ".tmp") tmp.writeBytes(out) + if (tmp.renameTo(metaFile)) return if (metaFile.exists()) metaFile.delete() if (!tmp.renameTo(metaFile)) { tmp.copyTo(metaFile, overwrite = true)