RecordObjectWrite tested `ferror(f) || fclose(f) != 0`. When ferror was
true the short circuit skipped fclose, and the branch then set f to NULL,
disarming the cleanup that would have closed it. Every unreadable entry
leaked a file descriptor inside a walk that already holds one DIR* per
recursion level.
Measured on 200 records whose fopen succeeds but whose read fails
(a symlink to a directory): 207 descriptors held before, 7 after.
Sample ferror and close unconditionally, then report either failure.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
_PC_PATH_MAX belongs to pathconf, not sysconf. On glibc _PC_PATH_MAX and
_SC_OPEN_MAX are both 4, so sysconf(_PC_PATH_MAX) silently returned the
open-file limit (524288 here) and the fallback allocated 512KB per link.
Where the two constants do not collide sysconf returns -1, which becomes
SIZE_MAX and makes calloc fail, so create would break on every symlink
whose st_size is 0.
readlink also does not terminate the buffer and truncates silently when
the target does not fit, so check the returned length rather than only
testing for -1.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
RecordObjectCompare computed its result as (int)(a - b) on uintmax_t and
intmax_t fields. That truncates: a difference which is an exact multiple
of 2^32 yields 0, so two records already known to differ compared equal
and diff dropped the change without any output.
$ fsnap diff old.fsnap new.fsnap # size 0 vs 4294967296
$ echo $?
0
The subtraction on intmax_t was also undefined on overflow. The explicit
casts are what kept -Wconversion quiet about all of it.
Replace them with cmp_intmax/cmp_uintmax helpers returning -1/0/1.
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 const to RecordObjectCompare parameters
- Add static to crc32_table and table_computed in hash.c
- Rename NewRecordObject to RecordObjectNew
- Replace magic number 8192 with BUFFER_SIZE in utility.c
- Unify comment style to /* */ across all files
- Standardize _POSIX_C_SOURCE to 200809L
- Remove unreachable dead code in diff.c
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.
Hash the followed target content with CRC-32 (hash.c/hash.h) and emit a FINGERPRINT field for non-directory records in create.c. Schema: TYPE|MODE|UID|GID|MTIME|SIZE|FINGERPRINT|TARGET per SPEC §17/§18.
Splits RecordObject, unpack, release, field and field_name out of list.c into types.c/types.h; declares field extern in the header with a single definition in types.c; adds src/types.c to SOURCES.