Merge 2FAS imports instead of replacing existing data#8
Merged
Conversation
Importing a 2FAS backup now appends its entries to the current list rather than wiping and replacing it. Duplicates are detected by normalised secret (whitespace stripped, upper-cased) and skipped, so re-importing the same file is a no-op. Imported groups are merged by id without duplicating existing ones, and services keep a stable per -group order with newly added entries appended after existing ones. The storage layer now parses the selected file and returns its data instead of copying it over the local store; OtpState performs the merge and persists the combined result. The import action reports a summary of how many entries were added and how many were ignored as duplicates.
- Fix dangling imported group references: copyWith(groupId: null) null-coalesces and kept the unresolvable id, making those services invisible in grouped view; add OtpService.withGroupId and use it - Persist the merged data before committing it to state so a failed save leaves the in-memory data untouched - Remap imported service ids that collide with existing ones - Tests: dangling-group fallback, id remapping, save-failure rollback, encrypted-backup import (password required / correct / wrong), and exact-match merge assertions instead of containsAll
henricook
force-pushed
the
feat/2fas-import-merge
branch
from
July 5, 2026 11:09
c85dcca to
5ea67c6
Compare
henricook
marked this pull request as ready for review
July 5, 2026 11:31
The persist-then-commit reorder let a debounced usage-save fire during the import's own save, potentially clobbering the merged data on disk with pre-import state. Cancel the timer at the start of the import, as the vault branch already does.
…vault Reconciles the import merge/append feature with the now-merged local vault (PR #5). Import persistence goes through the vault-aware _persistCurrentData() instead of a direct plaintext saveData, so importing while an encrypted vault is active re-encrypts into data.bin rather than writing decrypted secrets to data.json. The merge is committed to state then persisted, rolling back the in-memory merge if the persist fails. Adds a test asserting imports take the encrypted path when the vault is active.
Owner
Author
|
Thanks @spotco ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: merging means the result is written via the normal save path, so importing an encrypted backup persists decrypted secrets to data.json immediately. Main already does this on the first debounced usage-save, so this is not a new exposure, but the proper fix is the encrypted vault in #5 - suggest merging #5 first and rebasing this on top so imports persist through the vault when active.