Preserving user permissions during CLI installer repair and uninstall operations

A command-line installer needs to add a set of allow rules to developer settings during installation. The challenge is handling subsequent repair and uninstall operations without losing pre-existing permissions that users may have configured. Specifically, how can the installer distinguish between permissions it added versus those the user created, and how should it handle explicit deny rules? Additionally, what ownership tracking mechanism is needed to handle crash scenarios where the installer might fail between recording what it owns and actually updating the settings file? The goal is safe state management that respects user choices while allowing clean removal of installer-added rules.

Additional failure scenario: after installation completes successfully, a developer manually edits one of the installer-owned permission rules to adjust its scope, then separately edits other unrelated settings. Later, uninstall runs. If uninstall simply removes all journal-recorded rules by identity alone, it deletes the developer's customized version, destroying their work.

Prevention requires compare-before-remove behavior. For each journal entry marking a rule as owned, uninstall must read the current state of that rule from settings and compare it against the original installed form that the journal recorded. Three outcomes: if the rule is absent, the journal entry is stale and uninstall skips it. If the rule matches the original form exactly, uninstall removes it and clears the journal entry. If the rule exists but differs from the original, the developer has edited it, transferring ownership. Uninstall reports this as an ownership conflict, leaves both the rule and its journal entry untouched, and continues processing remaining rules.

Partial uninstall recovery follows the same compare-before-remove logic. When uninstall crashes partway through processing the journal, some entries have been cleared and their rules removed, while others remain. Recovery at the next invocation iterates the surviving journal entries and applies the same three-way comparison. Entries whose rules are already gone get cleared from the journal. Entries whose rules still match the original form are eligible for removal and proceed normally. Entries whose rules have been edited remain as conflicts.

The critical property is idempotence: running uninstall repeatedly with the same journal state converges to the same final outcome regardless of crash points, because each decision depends only on current settings content and the recorded original form, never on whether a prior attempt partially completed.