Three problems in load_in_memory, all visible from the command line:
An empty snapshot was treated as an error, though create() produces one
for an empty directory and list() accepts it. Diffing against it should
report every record of the other side as added or deleted.
A malformed record jumped to cleanup without setting errno and without
naming the offending line, so main() printed strerror() of whatever was
left over, normally 0:
$ fsnap diff old.fsnap malformed.fsnap
diff failed: Success
The enum Fields it passed to RecordObjectUnpack was uninitialised and
then discarded, even though list() uses the same out-parameter to say
which field failed.
Report parse failures the way list() does, with snapshot:line: field, and
give them the same distinct 128 status so main() does not append a second,
meaningless message. Guard qsort against the now-reachable NULL array, and
check fflush(stdout) as scan() already does.
$ fsnap diff old.fsnap malformed.fsnap
malformed.fsnap:3: unparsable line
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
- Replace global field variable with output parameter enum Fields *err
- Adopt single goto cleanup pattern across all functions
- Add errno preservation around cleanup in all modules
- Fix early return bug in create.c cleanup block
- Add ferror check in crc32() for silent read errors
- Document error contracts in all public headers
Add fsnap diff <old> <new> that compares two snapshots and reports
added (A), deleted (D), metadata changed (M), permissions changed (P),
and symlink target changed (L) records.
Both snapshots are loaded into memory, sorted by path using qsort,
and merged with a two-pointer algorithm. Residual records after the
merge are emitted as A or D. Escape sequences in paths are decoded
on output.
Also add GetTime accessor, set errno on load_in_memory failures
for meaningful error messages, and fix unused-variable warnings.