mirror of
https://github.com/fscotto/fsnap.git
synced 2026-11-26 03:09:51 +00:00
Checksum a symlink over its target string
e2b45e6left 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 beforee2b45e6and 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
This commit is contained in:
12
README.md
12
README.md
@@ -108,7 +108,7 @@ type|permissions|uid|gid|size|time|target|fingerprint|path
|
||||
| `size` | Size in bytes, as reported by `lstat` |
|
||||
| `time` | Modification time, seconds since the Unix epoch |
|
||||
| `target` | Symlink target returned by `readlink`; empty for non-symlink entries |
|
||||
| `fingerprint` | CRC32 checksum of the contents, for regular files only; `0` for every other type, including symlinks, whose contents are the `target` field |
|
||||
| `fingerprint` | CRC32 of the contents for a regular file, and of the target string for a symlink, which is what the link holds. `0` for a directory and for the types that cannot be read at all (FIFO, socket, device) |
|
||||
| `path` | Absolute path: the input root is resolved with `realpath`, then child names are appended; it is escaped |
|
||||
|
||||
### Escaping rules
|
||||
@@ -131,7 +131,7 @@ pathname:
|
||||
| `A` | Present only in the new snapshot |
|
||||
| `D` | Present only in the old snapshot |
|
||||
| `P` | Permissions are the first differing field |
|
||||
| `L` | Symlink target is the only differing field after the other compared fields match |
|
||||
| `L` | The symlink target changed. Checked before the fingerprint, which for a link is derived from the target, so the specific answer wins over the generic one |
|
||||
| `M` | Any other difference, including type, owner, size, time, or fingerprint |
|
||||
|
||||
`diff` reports a malformed input the way `list` does, as
|
||||
@@ -140,10 +140,10 @@ returns `128` internally; `main` maps it to exit status `1`.
|
||||
|
||||
## Behaviour worth knowing
|
||||
|
||||
- **Symlinks are not followed, anywhere.** Their metadata comes from `lstat()`
|
||||
and their target from `readlink()`. Nothing opens the path afterwards, so a
|
||||
symlink is recorded as itself rather than as its referent, and a broken one
|
||||
snapshots like any other.
|
||||
- **Symlinks are not followed, anywhere.** Their metadata comes from `lstat()`,
|
||||
their target from `readlink()`, and their fingerprint from that target string
|
||||
rather than from whatever it points at. Nothing opens the path, so a link to a
|
||||
directory and a broken link both snapshot like any other entry.
|
||||
- **Paths are absolute.** The input directory is resolved through `realpath()`
|
||||
before traversal; snapshots are tied to the machine and location where they
|
||||
were taken.
|
||||
|
||||
Reference in New Issue
Block a user