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:
Incido Developer committed 2026-10-05 19:33:07 +13:00
1 parent cf0e74b68d
commit 031d8570b4
7 files changed
+138 -21

No files matched your search

@@ -2,9 +2,11 @@ package org.incido.desktop
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Checkbox
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
@@ -20,6 +22,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
@@ -66,6 +69,8 @@ fun BackupActions(
var menuOpen by remember { mutableStateOf(false) }
var importStage by remember { mutableStateOf<ImportStage?>(null) }
var exportStage by remember { mutableStateOf<ExportStage?>(null) }
// M2 task 3: dedupe is ON by default; the confirm dialog exposes it.
var skipDuplicates by remember { mutableStateOf(true) }
fun say(message: String) { scope.launch { snackbar.showSnackbar(message) } }
@@ -131,6 +136,8 @@ fun BackupActions(
is ImportStage.Confirm -> ConfirmImportDialog(
preview = stage.preview,
skipExisting = skipDuplicates,
onSkipChange = { skipDuplicates = it },
onDismiss = { importStage = null },
onConfirm = {
importStage = null
@@ -141,9 +148,15 @@ fun BackupActions(
repository,
FileInputStream(stage.file),
stage.passphrase?.toCharArray(),
skipExisting = skipDuplicates,
)
}
}.onSuccess { say("Imported $it notes") }
}.onSuccess {
say(
"Imported ${it.imported} notes" +
if (it.skipped > 0) " · skipped ${it.skipped} already imported" else "",
)
}
.onFailure { say("Import failed: ${it.message}") }
}
},
@@ -225,6 +238,8 @@ private suspend fun startImport(
@Composable
private fun ConfirmImportDialog(
preview: BackupPreview,
skipExisting: Boolean,
onSkipChange: (Boolean) -> Unit,
onDismiss: () -> Unit,
onConfirm: () -> Unit,
) {
@@ -239,12 +254,13 @@ private fun ConfirmImportDialog(
"Exported by Incido ${preview.appVersion} on $exported",
style = MaterialTheme.typography.bodySmall,
)
Text(
"Existing notes are kept. (Re-importing the same file still duplicates — " +
"dedupe is M2 task 3.)",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.outline,
)
Row(verticalAlignment = Alignment.CenterVertically) {
Checkbox(checked = skipExisting, onCheckedChange = onSkipChange)
Text(
"Skip notes that are already here",
style = MaterialTheme.typography.bodyMedium,
)
}
}
},
confirmButton = { TextButton(onClick = onConfirm) { Text("Import") } },