mirror of
https://github.com/fscotto/fsnap.git
synced 2026-11-26 03:09:51 +00:00
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
20 lines
729 B
C
20 lines
729 B
C
#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
|
|
and would otherwise be indistinguishable from a failure. */
|
|
int crc32(FILE *stream, uint32_t *out);
|
|
|
|
#endif
|