Commit Graph

9 Commits

Author SHA1 Message Date
Fabio Scotto di Santolo
e2b45e6ca8 Fingerprint regular files only
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
2026-08-26 15:51:18 +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
4e56e3e37c Update README now that the sources declare no feature test macros
The Building section described _GNU_SOURCE as an open gap against
SPEC.md section 19. It was closed in e193783: the macros moved to the
Makefile and nothing behind them is outside POSIX.1-2008.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
2026-08-26 15:38:20 +02:00
Fabio Scotto di Santolo
0e890aecdc Update README where the fixes changed documented behaviour
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
2026-08-26 15:13:46 +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
f08692679f Update README.md 2026-08-23 18:43:04 +02:00
Fabio Scotto di Santolo
691988e505 Add SPEC.md and bring list, create and scan in line with it
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
2026-08-16 11:03:31 +02:00
Fabio Scotto di Santolo
bb049d57a9 Rewrite README to describe the tool as it actually is
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
2026-08-01 22:55:06 +02:00
Fabio Scotto di Santolo
af56ec524d Initial commit 2026-07-31 14:40:53 +02:00