From: Arvin Schnell Date: Thu, 13 Jan 2011 18:23:58 +0000 (+0100) Subject: - add tool to compare directories in the background X-Git-Tag: v0.1.3~547 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=793712c91e9ee96b7c6d4e481ab7446e34d1698f;p=thirdparty%2Fsnapper.git - add tool to compare directories in the background --- diff --git a/Makefile.am b/Makefile.am index 7bc18158..cb74d1ad 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/configure.in b/configure.in index 3c9e792f..07b921ac 100644 --- a/configure.in +++ b/configure.in @@ -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 index 00000000..bbbb2da8 --- /dev/null +++ b/tools/.gitignore @@ -0,0 +1,2 @@ +compare-dirs.o +compare-dirs diff --git a/tools/Makefile.am b/tools/Makefile.am new file mode 100644 index 00000000..9b62edf0 --- /dev/null +++ b/tools/Makefile.am @@ -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 index 00000000..543cb75d --- /dev/null +++ b/tools/compare-dirs.cc @@ -0,0 +1,71 @@ + +#include +#include +#include + +#include + +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); +}