Commit Graph

13 Commits

Author SHA1 Message Date
c63530da34 Implement snapshot verification command 2026-11-01 16:31:51 +01:00
Fabio Scotto di Santolo
be86f05d58 Implement stack data structure WIP 2026-08-27 00:11:35 +02:00
Fabio Scotto di Santolo
8c34ab4f4e Add a make valgrind target
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
2026-08-26 16:19:50 +02:00
Fabio Scotto di Santolo
aad607e5f0 Add a test suite and a make test target
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
2026-08-26 16:13:27 +02:00
Fabio Scotto di Santolo
25b328ba79 Add install and uninstall targets
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
2026-08-26 15:46:05 +02:00
Fabio Scotto di Santolo
e19378308d Declare feature test macros once in the build, not per source file
Nine files had drifted into four different combinations: _GNU_SOURCE in
walk.c, _XOPEN_SOURCE 700 in utility.c, _DEFAULT_SOURCE in scan.c,
_POSIX_C_SOURCE 200809L in list.c and diff.c, and all three at once in
create.c and types.c, where _XOPEN_SOURCE 700 already implies POSIX 2008.

_GNU_SOURCE was also wider than anything the code asks for: walk needs
dirent.d_type, which _DEFAULT_SOURCE provides. Closing that gap is what
SPEC.md section 19 asks for and what the README flags as the one thing
keeping the tree from being POSIX-only.

CPPFLAGS now carries -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE, and the
sources declare nothing. Confirmed DT_UNKNOWN is still visible under that
pair, so the d_type fast path stays active rather than silently falling
back to lstat.

Verified against the previous build: byte-identical scan output over
/usr/include, /usr/share/doc and /etc (17820 entries), and byte-identical
snapshots from create.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
2026-08-26 15:32:35 +02:00
Fabio Scotto di Santolo
1302d5a946 Build with -O2 and a stricter warning set, and fix what it found
Without optimisation GCC skips the flow analysis most of these warnings
are derived from, so -O2 is what makes the existing -W flags do their job.

The new flags found three real defects:

  -Wstrict-prototypes/-Wold-style-definition: init_crc32_table() and
  RecordObjectNew() were declared with (), which in C11 means "no
  prototype", not "no arguments". RecordObjectNew even contradicted its
  own header, which declares (void).

  -Wwrite-strings: walk's blacklist held string literals in a
  non-const char *[], so they were writable through the array.

Also make ignore_file size its loop with sizeof(blacklist[0]) instead of
repeating the element type, and drop the order-only build/ prerequisite
on the link rule, which the %.o rule's mkdir -p already covers.

The tree builds clean under all twelve flags.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
2026-08-26 15:13:08 +02:00
Fabio Scotto di Santolo
dcd17889ac Implement snapshot diff command
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.
2026-08-25 18:13:29 +02:00
Fabio Scotto di Santolo
e5f5d559bc Add CRC-32 fingerprinting of symlink targets
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.
2026-08-23 17:47:09 +02:00
Fabio Scotto di Santolo
9df9223b63 Extract snapshot parser into a reusable types module
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.
2026-08-21 00:00:23 +02:00
Fabio Scotto di Santolo
b542113252 Add list command [WIP] 2026-08-05 22:07:21 +02:00
Fabio Scotto di Santolo
3eae528f54 Add create command 2026-08-01 14:27:52 +02:00
Fabio Scotto di Santolo
078b95dc4b Add function scan directory 2026-07-31 23:54:45 +02:00