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