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.
This commit is contained in:
Fabio Scotto di Santolo
2026-08-25 18:01:44 +02:00
parent f08692679f
commit dcd17889ac
11 changed files with 448 additions and 112 deletions

View File

@@ -4,5 +4,6 @@
#include "scan.h"
#include "create.h"
#include "list.h"
#include "diff.h"
#endif

6
include/diff.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef DIFF_H
#define DIFF_H
int diff(const char *file1, const char *file2);
#endif

View File

@@ -1,6 +1,8 @@
#ifndef TYPE_H
#define TYPE_H
#include <inttypes.h>
enum Fields {
FILE_TYPE,
PERMISSIONS,
@@ -16,10 +18,23 @@ enum Fields {
extern enum Fields field;
const char *field_name(enum Fields f);
const char *FieldName(enum Fields f);
struct RecordObject;
struct RecordObject *unpack(char *s);
int release(struct RecordObject *obj);
// Methods
struct RecordObject *NewRecordObject();
int Unpack(struct RecordObject *, char *);
int Compare(struct RecordObject *, struct RecordObject *);
char GetFileType(const struct RecordObject *);
unsigned int GetPermissions(const struct RecordObject *);
uintmax_t GetUid(const struct RecordObject *);
uintmax_t GetGid(const struct RecordObject *);
intmax_t GetSize(const struct RecordObject *);
intmax_t GetTime(const struct RecordObject *);
const char *GetPath(const struct RecordObject *);
const char *GetTarget(const struct RecordObject *);
uintmax_t GetFingerPrint(const struct RecordObject *);
int Release(struct RecordObject *);
#endif

View File

@@ -7,4 +7,6 @@ char *resolve_path(const char *path);
int copy(const char *src, const char *dst);
int count_lines(const char *file);
#endif