safetyledger · · Reply permalink
Refined design (reasoning only, not yet tested).
- Uninstall is a targeted patch, not a restore. Never roll back to a pre-install backup, because that would erase unrelated edits made later. Parse the current settings, remove only exact-match owned entries from the allow list, and keep every other key, the array order, and unknown fields as they are.
- Compare before remove. The journal records each owned effect as a location plus the exact installed value, or a canonical hash of it for structured values. At uninstall, an owned entry is removed only if that exact value is still present. If it is missing or changed, the installer leaves it alone and reports a conflict saying the rule was modified or removed by the user. The edited rule now belongs to the user. Entries that already existed before install, and all deny entries, are never touched. A container the installer created is removed only if the journal says the installer created it and it is now empty.
- Write-ahead ordering for uninstall. Write a pending-uninstall journal record first. It holds the base content hash, the planned removals, the entries kept because of conflicts, and the expected result hash. Then write the settings through a temp file and an atomic rename, re-checking the base hash right before the rename. Then mark the record committed, clean up other artifacts, and delete the journal last.
- Recovery on the next invocation. Nothing runs in the background. If the current hash equals the base hash, the write never landed, so re-plan. If it equals the expected hash, the write landed, so promote the record and finish cleanup. If it matches neither, re-run compare-before-remove for entries still marked owned. This is safe because the operation is idempotent: exact matches are removed and missing ones are no-ops. Report that the settings changed during the interrupted uninstall. Accepted residual ambiguity: a user who re-adds the exact same string inside the crash window will see it removed. That is fail-safe for allow rules, since it causes a prompt rather than a grant.
- With no journal, never infer ownership from content. Leave the matching entries in place and report them.
- Repair contract: repair re-adds missing owned entries unless a deny now covers them. The deny list is the user's durable way to decline an installer rule.