Runs the existing suite with every fsnap invocation under memcheck,
rather than duplicating a list of commands in the Makefile: tests/run.sh
already funnels each call through fsnap(), so a command prefix is all it
takes. VALGRIND is empty for a plain `make test`.
-q keeps stderr clean, which matters because several tests compare it,
and --error-exitcode=99 turns a finding into a failing test instead of a
note nobody reads. The per-invocation timeout goes to 300s, since
memcheck costs an order of magnitude: the whole suite takes about 25
seconds against a fraction of a second without it.
Checked the same way as the suite itself. Dropping the free() of the
getline buffer in list keeps `make test` green at 91 passed while `make
valgrind` fails, which is the whole point of having it. Replacing the
calloc in RecordObjectNew with malloc is caught too, and named precisely:
free() on an uninitialised value at types.c:420. Baseline green either
side, and the missing-valgrind guard exits 2 with a clear message.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
91 black-box checks in tests/run.sh, driving the built binary because
that is the only interface the tool has. POSIX sh, no dependencies, no
framework; TAP-ish output and a non-zero exit when anything fails.
Covers the tree shapes SPEC.md section 22 asks for -- regular and empty
files, nested directories, symlinks, broken symlinks, symlinks to
directories, hard links, FIFOs, sockets, unusual filenames and permission
errors -- the parser cases from sections 14 and 15, the diff
classifications, argument handling, and the resource rules from sections
9 and 11. What the environment cannot provide is skipped, not failed.
Every bug fixed in this branch is pinned by a test: the 2^32 comparison
truncation, the symlink checksum, target-before-fingerprint ordering, the
mkstemp template unlink, errno surviving a cleanup failure, the empty
snapshot in diff, and create over each entry type that used to abort it.
Invocations run under timeout(1) where it exists. Without it a walker
regression makes create block on a FIFO forever, which hangs the suite
instead of failing it -- found by reintroducing exactly that bug.
Checked by mutation: seven deliberate regressions, one per fix, each
caught by the test written for it, with the baseline green either side.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
e2b45e6 left symlinks with fingerprint 0 on the grounds that the target
field already describes them. Restore a real checksum for them, computed
over the target string readlink reports -- which is what the link
actually holds on disk -- rather than over the referent's contents, which
is what the code did before e2b45e6 and what made `create /etc` fail with
EISDIR on the 13 links there that point at directories.
Adds crc32_buffer for the in-memory case. Values agree with zlib.crc32
of the same string.
Directories keep 0, and so do FIFOs, sockets and devices: those cannot be
read at all rather than merely being awkward to read. A FIFO blocks until
a writer appears, which is an indefinite hang, not an error.
Also reorder RecordObjectCompare to test target before fingerprint. Since
a link's fingerprint is now a function of its target, the old order
reported a changed target as a changed checksum, and diff printed M where
it should print L. The fields are now compared in the order the record
stores them.
Verified: all 1236 symlinks in a tree shaped like /etc get a non-zero
fingerprint and the walk completes; L, M and P classifications confirmed
individually; valgrind clean.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
create checksummed every entry that was not a directory, which meant it
called fopen on symlinks, FIFOs, sockets and devices. fopen follows
symlinks, so a link to a directory failed with EISDIR -- which is what
`fsnap create /etc` hits, /etc holding 13 of them:
$ fsnap create /etc snapshot.fsnap
create failed: Is a directory
Each of the other types failed its own way: a broken symlink with ENOENT,
a socket with ENXIO, and a FIFO by blocking forever waiting for a writer.
Only a regular file has contents worth checksumming, and only a regular
file is safe to open. A symlink is already fully described by its target
field, so checksumming its referent was answering a different question
anyway. Everything that is not a regular file now keeps fingerprint 0.
This changes recorded fingerprints for symlinks, from the referent's
checksum to 0. The format carries no version yet, so old snapshots will
diff as modified against new ones.
Verified over a tree rebuilt with the exact shape of /etc -- 1597 regular
files, 1236 symlinks including 13 pointing at directories, 449
directories -- which now completes with all 3282 records valid, and over
the four failing types in isolation.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
install copies the binary to $(BINDIR), defaulting to /usr/local/bin.
PREFIX, BINDIR and INSTALL are overridable, and DESTDIR is honoured so a
packager can stage into a temporary root; it is deliberately left
undefaulted rather than set to empty.
uninstall removes what install placed, and is idempotent.
Both use install(1) rather than cp, so the mode is set explicitly and the
target directory is created in the same step. The flags used, -d and -m,
are common to GNU and BSD install, which SPEC.md section 19 asks for.
Verified: staged install under DESTDIR, PREFIX and BINDIR overrides,
uninstall in both plain and staged form, uninstall with nothing to
remove, and install from a clean tree rebuilding first.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
diff now reports snapshot:line: field for a malformed record instead of
failing with a bare errno, and accepts an empty snapshot. The build
already uses -O2, so drop it from the roadmap.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
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.
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