Skip to content

fix: fail closed on unsafe sync operations - #5

Merged
ssalentin merged 2 commits into
mainfrom
sync-failsafe
Oct 18, 2026
Merged

ssalentin merged 2 commits into
mainfrom
sync-failsafe

Conversation

@ssalentin

Copy link
Copy Markdown
Owner

Summary

Hardens the device-sync pipeline so destructive operations fail closed.

  • A read or metadata failure during either scan now aborts before stale-file deletion. A genuinely empty directory is still treated as a valid empty source.
  • Stale deletion uses the real on-disk device paths, reports only files actually removed, and fails the sync on a real removal error.
  • FAT finalization now requires a successful read of the mount table with no entry for the resolved block device before running fatsort. Unknown mount state refuses with a manual-action error.

Verification

  • cargo test: 42 passed, 0 failed, 1 intentionally ignored.
  • Independent review: PASS on dbfdab1.
  • Independent QA: PASS, including PATH-shim injection through the real child-process path for failed, still-mounted, and provably-unmounted mount-table outcomes.
  • Non-root unreadable-subdirectory scan test passes.
  • git diff --check: clean.

Scoped gap: no physical FAT media was available for a real fatsort invocation. Rustfmt and Clippy still report pre-existing debt elsewhere in the checkout; this change adds no new findings.

A read_dir or metadata failure during scan_music_dir silently shrank the
source map, so run_rsync_device could delete valid device files that were
merely missing from the incomplete scan. Scans now return an error, which
aborts before any stale deletion; an empty directory still scans as
successfully empty.

Stale deletion now uses the real on-disk paths from the device scan and
fails the sync when a removal fails instead of logging a success that can
be larger than the number of files actually removed.

finalize_fat now asks findmnt whether the resolved block device still has
any mount target before running fatsort, and refuses with a manual-action
error when it does.
findmnt exits 1 both when a source has no mount target and when the
query itself fails, so the previous check could not tell them apart and
would let fatsort run on a device whose mount state was unknown.

Read the whole SOURCE,TARGET table instead: a successful read with no
entry for the device is positive proof it is unmounted, while a failed
read now refuses with a manual-action error. Add regression coverage for
the failed-query distinction.
@ssalentin
ssalentin merged commit bb278a4 into main Oct 18, 2026
1 check passed
@ssalentin
ssalentin deleted the sync-failsafe branch October 18, 2026 15:07
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