Skip to content

feat: confirm + reversible DNS and hosts changes#810

Merged
laurentiu021 merged 1 commit into
mainfrom
feat/2b-network-confirm-reversibility
Jun 8, 2026
Merged

feat: confirm + reversible DNS and hosts changes#810
laurentiu021 merged 1 commit into
mainfrom
feat/2b-network-confirm-reversibility

Conversation

@laurentiu021

Copy link
Copy Markdown
Owner

Round 2b of the audit — network mutations now confirm and are properly reversible.

Hosts file backup (P1 fix — data loss of the original)

SaveHosts copied the live hosts file over hosts.bak on every save (overwrite: true). After the first save the backup already contained SysManager's own output, so the pristine pre-SysManager original was gone and restore was impossible. Now the backup is written only when none exists, preserving the true original. Added HasBackup + RestoreBackup.

Confirmation gates

ApplyDns and SaveHosts now prompt with DialogService.Confirm first, stating what changes and how to revert. Declining makes no system change.

Reversibility (new capability)

New RestoreHosts command + "Restore original" button (with AutomationProperties.Name) reverts the hosts file to the pristine backup.

Testability

HostsFileService gained a path-injection constructor (testing only — DI still uses the parameterless path). New HostsFileServiceTests:

  • pristine backup preserved across multiple saves
  • restore returns the byte-exact original
  • no-backup → RestoreBackup returns false

Verification

dotnet build main + tests: 0 warnings, 0 errors. CHANGELOG + ARCHITECTURE updated; version 1.20.0 (feat → minor).

Round 2b of the audit — network mutations now confirm and are reversible.

- HostsFileService.SaveHosts no longer overwrites the backup on every save.
  Previously File.Copy(..., overwrite: true) ran each save, so after the first
  write hosts.bak already held SysManager's own output and the pristine original
  was gone. Now the backup is created only when none exists, preserving the true
  pre-SysManager file. Added HasBackup + RestoreBackup, and a path-injection
  constructor so backup/restore is unit-testable without admin or System32.
- DnsHostsViewModel: ApplyDns and SaveHosts now require DialogService.Confirm,
  stating what changes and how to revert; declining makes no change. Added a
  RestoreHosts command + 'Restore original' button (with AutomationProperties.Name).

Tests: HostsFileServiceTests covers pristine-backup preservation across saves,
restore-to-original, and no-backup handling.
@laurentiu021 laurentiu021 merged commit ce41cff into main Jun 8, 2026
4 checks passed
@laurentiu021 laurentiu021 deleted the feat/2b-network-confirm-reversibility branch June 8, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant