]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- add tool to compare directories in the background
authorArvin Schnell <aschnell@suse.de>
Thu, 13 Jan 2011 18:23:58 +0000 (19:23 +0100)
committerArvin Schnell <aschnell@suse.de>
Thu, 13 Jan 2011 18:23:58 +0000 (19:23 +0100)
Makefile.am
configure.in
tools/.gitignore [new file with mode: 0644]
tools/Makefile.am [new file with mode: 0644]
tools/compare-dirs.cc [new file with mode: 0644]

index 7bc181587d152ef8839f857624b8cbafa1a781c5..cb74d1adb732244d1f476314803b09491a22a13b 100644 (file)
@@ -2,7 +2,7 @@
 # Makefile.am for snapper
 #
 
-SUBDIRS = snapper examples cli
+SUBDIRS = snapper examples cli tools
 
 AUTOMAKE_OPTIONS = foreign dist-bzip2 no-dist-gzip
 
index 3c9e792f7769b27eedeee62326d0852bdb7d9f89..07b921ac8903e8a500d572f4a35f5db3bc3c048e 100644 (file)
@@ -32,6 +32,7 @@ AC_OUTPUT(
        Makefile
        snapper/Makefile
        examples/Makefile
+       tools/Makefile
        cli/Makefile
        package/snapper.spec:snapper.spec.in
 )
diff --git a/tools/.gitignore b/tools/.gitignore
new file mode 100644 (file)
index 0000000..bbbb2da
--- /dev/null
@@ -0,0 +1,2 @@
+compare-dirs.o
+compare-dirs
diff --git a/tools/Makefile.am b/tools/Makefile.am
new file mode 100644 (file)
index 0000000..9b62edf
--- /dev/null
@@ -0,0 +1,14 @@
+#
+# Makefile.am for snapper/tools
+#
+
+INCLUDES = -I$(top_srcdir)
+
+LDADD = ../snapper/libsnapper.la
+
+toolsbindir = /usr/lib/snapper/bin
+
+toolsbin_PROGRAMS = compare-dirs
+
+compare_dirs_SOURCES = compare-dirs.cc
+
diff --git a/tools/compare-dirs.cc b/tools/compare-dirs.cc
new file mode 100644 (file)
index 0000000..543cb75
--- /dev/null
@@ -0,0 +1,71 @@
+
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+
+#include <snapper/Files.h>
+
+using namespace snapper;
+using namespace std;
+
+
+char* tmp_name = NULL;
+
+FILE* file = NULL;
+
+
+void
+terminate(int)
+{
+    if (file != NULL)
+       fclose(file);
+
+    if (tmp_name != NULL)
+       unlink(tmp_name);
+
+    exit(EXIT_FAILURE);
+}
+
+
+void
+write_line(const string& name, unsigned int status)
+{
+    fprintf(file, "%s %s\n", statusToString(status).c_str(), name.c_str());
+}
+
+
+int
+main(int argc, char** argv)
+{
+    if (argc != 4)
+    {
+       fprintf(stderr, "usage: compare-dirs path1 path2 output\n");
+       exit(EXIT_FAILURE);
+    }
+
+    daemon(0, 0);
+
+    struct sigaction act;
+    act.sa_handler = terminate;
+    sigemptyset(&act.sa_mask);
+    act.sa_flags = 0;
+
+    sigaction(SIGINT, &act, NULL);
+    sigaction(SIGTERM, &act, NULL);
+
+    tmp_name = (char*) malloc(strlen(argv[3]) + 12);
+    strcpy(tmp_name, argv[3]);
+    strcat(tmp_name, ".tmp-XXXXXX");
+
+    int fd = mkstemp(tmp_name);
+
+    file = fdopen(fd, "w");
+
+    cmpDirs(argv[1], argv[2], write_line);
+
+    fclose(file);
+
+    rename(tmp_name, argv[3]);
+
+    exit(EXIT_SUCCESS);
+}