mirror of
https://github.com/fscotto/fsnap.git
synced 2026-11-26 03:09:51 +00:00
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:
21
src/main.c
21
src/main.c
@@ -6,7 +6,7 @@
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "%s: command not found [scan|create|list]\n", argv[0]);
|
||||
fprintf(stderr, "%s: command not found [scan|create|list|diff]\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
} else if (strcmp(cmd, "list") == 0) {
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "%s: command %s expected param [snapshot_file]", argv[0],
|
||||
fprintf(stderr, "%s: command %s expected param [snapshot_file]\n", argv[0],
|
||||
cmd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -54,6 +54,23 @@ int main(int argc, char *argv[]) {
|
||||
} else if (ret > 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
} else if (strcmp(cmd, "diff") == 0) {
|
||||
if (argc < 4) {
|
||||
fprintf(stderr,
|
||||
"%s: command %s expected params [snapshot_file1 snapshot_file2]\n",
|
||||
argv[0], cmd);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
const char *snapshot1 = argv[2];
|
||||
const char *snapshot2 = argv[3];
|
||||
int ret = diff(snapshot1, snapshot2);
|
||||
if (ret == -1) {
|
||||
const int err = errno;
|
||||
fprintf(stderr, "diff failed: %s\n", strerror(err));
|
||||
return EXIT_FAILURE;
|
||||
} else if (ret > 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "command %s is not valid\n", cmd);
|
||||
return EXIT_FAILURE;
|
||||
|
||||
Reference in New Issue
Block a user