Commit Graph
1 Commits
Author SHA1 Message Date
ggbdpqandfactory-droid[bot] 671e2b44e6 backup: a backup file a BOM-writing tool saved over still opens (#1567, ggbdpq)
What changed: Open reads through a UTF-8 byte order mark in front of the
sealed JSON (edit.TrimBOM, the trim #1534 gives a file read some other
way than edit.Read). The backup file is written back through
edit.WriteAtomic, which keeps the mark the file at that path starts with,
so a backup a Windows editor's "UTF-8 with BOM" or PowerShell 5.1's
Set-Content put a mark on opens as it is, where it read as "not a magpie
backup" — and, in a sync, ranked as a file never to rebuild over.

Test: TestOpenReadsThroughABOM (backup.Open, three shapes: a marked
sealed backup opens with its bundle whole; a marked page that is no
backup is still ErrNotBackup; a marked backup cut short is still
ErrCorrupt, so a sync may still rebuild it) fails on the old code with
"a backup with a byte order mark: not a magpie backup" and passes now;
the backup and davsync packages' other tests pass unchanged.

Run: go test -tags nogui -count=1 ./internal/backup ./internal/davsync;
gofmt -l; go vet and go build on darwin, GOOS=linux -tags nogui and
GOOS=windows.

Review: reproduced on main (3f5702421). Added
TestBackupSavedOverAMarkedFileRestores, magpie's own round trip: `magpie
backup f` over a file that starts with a mark keeps the mark (WriteAtomic's
keepBOM), and `magpie restore f` then said "not a magpie backup". Both
tests go red with the TrimBOM line taken out by hand and green with it.
OpenData is left as it is: its files only come back from the sync server
as magpie PUT them, never through WriteAtomic over a user's file.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-10-11 12:00:41 +08:00