feat(phase-1/m2.3): import dedupe — importing the same file twice adds nothing
Phase 1 M2 task 3 (tools/DESKTOP_PHASE_PLAN.md §4). Logic lives in BackupBridge so both platforms get it through the one bridge: - BackupBridge.import gains skipExisting (default true) and returns ImportSummary(imported, skipped). A note is skipped when the library already holds the key (createdAt, updatedAt, sha256(content)) — the triple the export preserves verbatim, trustworthy only since the M2 import-timestamp fix. Keys are snapshotted BEFORE importing, so two genuinely identical notes inside one file still both import into a fresh library; only a second import of the same file is a no-op. Snapshotted keys include trashed notes. skipExisting=false restores the old additive behaviour (the documented override). - Android: BackupManager.import passes the flag and returns the summary (signature-identical call for SettingsViewModel); its snackbar now reports the skip count. Screen layouts untouched — exit criterion "Android backup screens unchanged" holds. - Desktop: the import confirm dialog swaps its "duplicates persist" warning for a working "Skip notes that are already here" checkbox (default ON); scripted path prints the re-import outcome. - Format unchanged: formatVersion stays 1 (streaming/dedupe-at-format level stays a Phase-2 formatVersion=2 idea). Verification passed: :core:data-jvm:backupSmoke (new step — re-import skipped=27, override added 27, store=54; RESULT M2 round-trip PASS on the real export) + :desktopApp:run --args="--data-dir /tmp/incido-m2t3 --backup-import <export> --backup-export … --exit-after 8" (imported=27 skipped=0 → exported=27 → reimport imported=0 skipped=27, clean exit) + assembleDebug + :core:data-jvm:smoke + :desktopApp:run --self-test — all green; output recorded in DESKTOP_FEASIBILITY.md. Known limitation (by design): attachments are not in the key.
This commit is contained in:
1 parent
cf0e74b68d
commit
031d8570b4
7 files changed
+138
-21
No files matched your search
@@ -74,7 +74,7 @@ fun main(args: Array<String>) {
|
||||
|
||||
step("import into fresh JVM library") {
|
||||
ObjectBoxStore.init(libDir)
|
||||
val n = runBlocking { BackupBridge.import(repo(), FileInputStream(src)) }
|
||||
val n = runBlocking { BackupBridge.import(repo(), FileInputStream(src)).imported }
|
||||
require(n == original.notes.size) { "imported $n, expected ${original.notes.size}" }
|
||||
val inStore = runBlocking { repo().observeAllIncludingTrashed().first().size }
|
||||
require(inStore == original.notes.size) { "store holds $inStore" }
|
||||
@@ -110,7 +110,7 @@ fun main(args: Array<String>) {
|
||||
ObjectBoxStore.reset()
|
||||
val dir2 = File(libDir.absolutePath + "-enc").also { it.deleteRecursively(); it.mkdirs() }
|
||||
ObjectBoxStore.init(dir2)
|
||||
val n = runBlocking { BackupBridge.import(repo(), ByteArrayInputStream(envelope), pw()) }
|
||||
val n = runBlocking { BackupBridge.import(repo(), ByteArrayInputStream(envelope), pw()).imported }
|
||||
require(n == original.notes.size) { "imported $n, expected ${original.notes.size}" }
|
||||
val withAtt = runBlocking { repo().observeAllIncludingTrashed().first() }
|
||||
.first { it.attachments.isNotEmpty() }
|
||||
@@ -121,6 +121,21 @@ fun main(args: Array<String>) {
|
||||
require(bytes.contentEquals(expected)) { "attachment bytes differ (${bytes.size} vs ${expected.size})" }
|
||||
"imported $n notes; attachment ${bytes.size}B byte-identical to the phone's"
|
||||
}
|
||||
step("dedupe: re-import same file") {
|
||||
ObjectBoxStore.reset()
|
||||
val dir3 = File(libDir.absolutePath + "-dedupe").also { it.deleteRecursively(); it.mkdirs() }
|
||||
ObjectBoxStore.init(dir3)
|
||||
val first = runBlocking { BackupBridge.import(repo(), FileInputStream(src)) }
|
||||
require(first.imported == original.notes.size && first.skipped == 0) { "first=$first" }
|
||||
val again = runBlocking { BackupBridge.import(repo(), FileInputStream(src)) }
|
||||
require(again.imported == 0 && again.skipped == original.notes.size) { "again=$again" }
|
||||
// The override must still behave like the old additive import.
|
||||
val forced = runBlocking { BackupBridge.import(repo(), FileInputStream(src), skipExisting = false) }
|
||||
require(forced.imported == original.notes.size) { "forced=$forced" }
|
||||
val count = runBlocking { repo().observeAllIncludingTrashed().first().size }
|
||||
require(count == original.notes.size * 2) { "store holds $count after forced re-import" }
|
||||
"re-import skipped=${again.skipped}; override added ${forced.imported} (store=$count)"
|
||||
}
|
||||
step("close libraries") {
|
||||
ObjectBoxStore.reset()
|
||||
"clean"
|
||||
|
||||
Reference in new issue
Block a user