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.
This commit is contained in:
Fabio Scotto di Santolo
2026-08-23 17:47:09 +02:00
parent 9df9223b63
commit e5f5d559bc
6 changed files with 137 additions and 7 deletions

View File

@@ -5,12 +5,13 @@
#include <stdlib.h>
#include <string.h>
#define NFIELDS 7
#define NFIELDS 9
enum Fields field = NONE;
static const char *field_names[] = {"file type", "permissions", "uid", "gid",
"size", "time", "path", "none"};
static const char *field_names[] = {
"file type", "permissions", "uid", "gid", "size",
"time", "target", "fingerprint", "path", "none"};
const char *field_name(enum Fields f) {
return (f <= NONE) ? field_names[f] : "unknown";
@@ -177,6 +178,8 @@ struct RecordObject {
intmax_t size;
intmax_t time;
char *path;
char *target; /* only for symlink */
uintmax_t fingerprint;
};
struct RecordObject *unpack(char *s) {
@@ -221,13 +224,31 @@ struct RecordObject *unpack(char *s) {
return objp;
}
if (fields[6][0] == '\0') {
errno = 0;
char *target = unescape_path(fields[6], '|');
if (target == NULL) {
if (errno == EINVAL) {
field = TARGET;
return objp;
}
release(objp);
return NULL;
}
objp->target = target;
if (parse_uintmax(fields[7], &objp->fingerprint) == -1) {
field = FINGERPRINT;
return objp;
}
if (fields[8][0] == '\0') {
field = PATH;
return objp;
}
errno = 0;
char *path = unescape_path(fields[6], '|');
char *path = unescape_path(fields[8], '|');
if (path == NULL) {
if (errno == EINVAL) {
field = PATH;
@@ -250,6 +271,10 @@ int release(struct RecordObject *obj) {
free(obj->path);
obj->path = NULL;
}
if (obj->target != NULL) {
free(obj->target);
obj->target = NULL;
}
free(obj);
return 0;