Skip to content

fix: preserve all hostnames per IP and write hosts file atomically#882

Merged
laurentiu021 merged 1 commit into
mainfrom
fix/hosts-data-loss-atomic-write
Jun 12, 2026
Merged

fix: preserve all hostnames per IP and write hosts file atomically#882
laurentiu021 merged 1 commit into
mainfrom
fix/hosts-data-loss-atomic-write

Conversation

@laurentiu021

Copy link
Copy Markdown
Owner

Summary

Two P1 reliability fixes in HostsFileService.

Fixes

  • Data loss (hosts-05): ReadHostsAsync took only tokens[1] (the first hostname) from each line, so 127.0.0.1 a b c lost b/c on a read→save round trip. Now emits one HostsEntry per hostname so all survive.
  • Non-atomic write (hosts-09): SaveHosts called File.WriteAllLines directly over the live hosts file; a crash mid-write could leave it empty/truncated. Now writes to hosts.sysmanager.tmp then File.Move(..., overwrite: true) for an atomic replace, with temp cleanup in finally.

Tests (the service previously had only backup/restore coverage)

  • ReadHostsAsync_MultipleHostnamesPerIp_AllPreserved — asserts alpha/beta/gamma all round-trip.
  • SaveHosts_LeavesNoTempFileBehind — asserts the atomic-write temp file is gone after save and content is correct.
    Both use the existing path-injection NewServiceWithTempHosts helper (no real System32 hosts touched, no admin).

Verification

  • Build: main + Tests 0 warnings / 0 errors.

fix: → patch release (1.20.24). Protocol C to follow.

@laurentiu021 laurentiu021 merged commit a06f018 into main Jun 12, 2026
4 checks passed
@laurentiu021 laurentiu021 deleted the fix/hosts-data-loss-atomic-write branch June 12, 2026 15:28
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