_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.
A filename may contain any byte except NUL and '/', so it may contain the
field delimiter or a newline. Until now create wrote such paths verbatim:
a name with '|' shifted the field layout and a name with a newline split
the record in two, and list could only reject the result.
create now escapes the path before writing it -- '\' as '\\', '|' as
'\|', and a newline as '\n' -- and list decodes it back. The backslash
has to be escaped as well: without it '\|' would be ambiguous between an
escaped delimiter and a literal backslash followed by a delimiter.
Splitting stays escape-unaware on purpose. Only the path may hold an
escaped delimiter and it is the last of the seven fields, so the six
separators found while splitting are always the real ones; the check that
used to reject a delimiter in the last field moves into the unescaper,
which has the context to tell a valid escape from a malformed one. It
rejects a bare delimiter, an unknown escape, and a trailing backslash,
and reports them as an invalid path field rather than an unparsable line.
walk guards the d_type fast path with #ifdef DT_UNKNOWN and falls back to
the lstat path when the constants are unavailable, which SPEC 4.1 already
requires and which POSIX-only feature test macros need, since d_type is a
BSD extension rather than part of POSIX.
Verified by decoding every record of three trees -- one with pipes,
backslashes and a newline in the names, the SPEC 22 tree, and this
repository -- and confirming lstat finds all 315 decoded paths.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F3NNME8GifswDYLr9VpBzs
SPEC.md records the design the project has been following: goals, staged
plan, and the rules for parsing, error handling and resource ownership.
Conformance fixes it made visible:
- list: accept the `?` file type that create legitimately writes; read
records with getline so long paths are no longer truncated at a fixed
buffer size (SPEC 13); reject numeric fields that are not bare digits
and check ERANGE, so out-of-range values and negative uid/gid no
longer wrap silently (SPEC 14); release the record when the path
allocation fails (SPEC 11).
- list, create: keep the errno of the failure that actually occurred.
An error raised before the cleanup owns errno and is restored; one
raised by fclose owns it only when nothing had failed yet, which is
the case a buffered write can hit for the first time at close
(SPEC 8, SPEC 10).
- scan: propagate printf failures and check fflush(stdout), so a write
error to a redirected stdout is no longer silently ignored (SPEC 8).
- An empty snapshot is a valid snapshot with zero records, not an
error: create produces one for an empty directory.
README.md now documents list, points at SPEC.md where the two differ,
and drops the roadmap entry that proposed renaming list to verify --
SPEC 12 defines list as the parser and SPEC 18 reserves verify for
comparing a snapshot against the live filesystem.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F3NNME8GifswDYLr9VpBzs
The previous text advertised inode data, hard-link tracking, snapshot
comparison and verification, none of which exist. Replace it with what the
code does today: the scan and create commands, the seven-field record
format, and the behaviour around symlinks, absolute paths, unreadable
directories and the .fsnap filter.
State plainly that this is a hobby project and not production ready, list
the limitations that are known and reproducible — non-atomic output, one
directory handle per recursion level, no exit code for a partial snapshot,
no quoting for paths containing a pipe or a newline, no hard-link data, no
tests — and record the intended work as a roadmap.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mbj1ZPUEhxqMYKsK7Y7jkt
opendir() failing with EACCES now warns on stderr and lets the walk carry
on with the rest of the tree. The record for the directory itself is still
written, since the operation runs before the recursion, so its metadata
survives even when its contents cannot be listed. Every other opendir
error still propagates.
Also check the return value of fprintf when writing a record, close the
descriptor when fdopen fails, and move the strings.h include to the file
that actually calls strcasecmp.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mbj1ZPUEhxqMYKsK7Y7jkt
- create: write the snapshot to a temporary file and copy it into place
only after the walk succeeds; every failure now propagates through rc
instead of being reported as success, and the temporary is unlinked on
all exit paths
- create: skip snapshot files by matching the ".fsnap" suffix against the
basename, so entries below a directory whose name contains ".fsnap" are
no longer dropped from the snapshot
- walk: emit a record for directories as well as leaf files, honour the
return value of the operation callback, and free the path and close the
directory handle on every exit path
- utility: replace the fixed-size realpath buffer with realpath(NULL) and
add copy(), which reports read, write and close errors instead of
silently truncating the destination
- scan, create: set errno to EINVAL on invalid arguments so main can print
a meaningful message
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mbj1ZPUEhxqMYKsK7Y7jkt