Checksum a symlink over its target string

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
This commit is contained in:
Fabio Scotto di Santolo
2026-08-26 16:01:06 +02:00
parent e2b45e6ca8
commit 0417bd825a
4 changed files with 39 additions and 21 deletions

View File

@@ -1,9 +1,15 @@
#ifndef HASH_H
#define HASH_H
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
/* Compute the CRC-32 checksum of a memory buffer. Cannot fail, so the result
is returned directly. Used for a symlink, whose content is the target string
readlink reports rather than anything reachable through the filesystem. */
uint32_t crc32_buffer(const void *data, size_t length);
/* Compute the CRC-32 checksum of the stream's remaining contents into *out.
Returns 0 on success, -1 on read error, leaving *out untouched. The result
is reported through an out parameter because 0 is a perfectly good checksum