diff options
Diffstat (limited to 'src/syrep.c')
-rw-r--r-- | src/syrep.c | 104 |
1 files changed, 78 insertions, 26 deletions
diff --git a/src/syrep.c b/src/syrep.c index fadb7e5..f95f086 100644 --- a/src/syrep.c +++ b/src/syrep.c @@ -31,6 +31,7 @@ #include <unistd.h> #include <stdlib.h> #include <errno.h> +#include <signal.h> #include "md5util.h" #include "md5.h" @@ -48,6 +49,9 @@ #include "dump.h" #include "extract.h" #include "makepatch.h" +#include "cleanup.h" + +volatile int interrupted = 0; struct gengetopt_args_info args; @@ -63,15 +67,15 @@ static int do_diff(void) { } if (args.local_temp_flag && isdirectory(args.inputs[0]) >= 1) { - const char *p = get_attached_filename(args.inputs[0], SYREP_TEMPDIR); + const char *p = get_snapshot_filename(args.inputs[0], SYREP_TEMPDIR); mkdir(p, 0777); setenv("TMPDIR", p, 1); } - if (!(path1 = strdup(get_attached_filename(args.inputs[0], SYREP_SNAPSHOTFILENAME)))) + if (!(path1 = strdup(get_snapshot_filename(args.inputs[0], SYREP_SNAPSHOTFILENAME)))) goto finish; - if (!(path2 = strdup(get_attached_filename(args.inputs[1], SYREP_SNAPSHOTFILENAME)))) + if (!(path2 = strdup(get_snapshot_filename(args.inputs[1], SYREP_SNAPSHOTFILENAME)))) goto finish; if (!strcmp(path1, path2)) { @@ -79,10 +83,10 @@ static int do_diff(void) { goto finish; } - if (!(c1 = db_context_open(path1))) + if (!(c1 = db_context_open(path1, 0))) goto finish; - if (!(c2 = db_context_open(path2))) + if (!(c2 = db_context_open(path2, 0))) goto finish; if (!(ddb = make_diff(c1, c2))) @@ -128,15 +132,15 @@ static int do_merge(void) { } if (args.local_temp_flag) { - const char *p = get_attached_filename(args.inputs[1], SYREP_TEMPDIR); + const char *p = get_snapshot_filename(args.inputs[1], SYREP_TEMPDIR); mkdir(p, 0777); setenv("TMPDIR", p, 1); } - if (!(path1 = strdup(get_attached_filename(args.inputs[0], SYREP_SNAPSHOTFILENAME)))) + if (!(path1 = strdup(get_snapshot_filename(args.inputs[0], SYREP_SNAPSHOTFILENAME)))) goto finish; - if (!(path2 = strdup(get_attached_filename(args.inputs[1], SYREP_SNAPSHOTFILENAME)))) + if (!(path2 = strdup(get_snapshot_filename(args.inputs[1], SYREP_SNAPSHOTFILENAME)))) goto finish; if (!strcmp(path1, path2)) { @@ -144,10 +148,13 @@ static int do_merge(void) { goto finish; } - if (!(c1 = db_context_open(path1))) + if (!(c1 = db_context_open(path1, 0))) goto finish; - if (!(c2 = db_context_open(path2))) + if (!(c2 = db_context_open(path2, 0))) + goto finish; + + if (db_context_origin_warn(c2)) goto finish; if (merge(c1, c2, args.inputs[1]) < 0) @@ -187,15 +194,15 @@ static int do_makepatch(void) { } if (args.local_temp_flag) { - const char *p = get_attached_filename(args.inputs[0], SYREP_TEMPDIR); + const char *p = get_snapshot_filename(args.inputs[0], SYREP_TEMPDIR); mkdir(p, 0777); setenv("TMPDIR", p, 1); } - if (!(path1 = strdup(get_attached_filename(args.inputs[0], SYREP_SNAPSHOTFILENAME)))) + if (!(path1 = strdup(get_snapshot_filename(args.inputs[0], SYREP_SNAPSHOTFILENAME)))) goto finish; - if (!(path2 = strdup(get_attached_filename(args.inputs[1], SYREP_SNAPSHOTFILENAME)))) + if (!(path2 = strdup(get_snapshot_filename(args.inputs[1], SYREP_SNAPSHOTFILENAME)))) goto finish; if (!strcmp(path1, path2)) { @@ -203,12 +210,15 @@ static int do_makepatch(void) { goto finish; } - if (!(c1 = db_context_open(path1))) + if (!(c1 = db_context_open(path1, 0))) goto finish; - if (!(c2 = db_context_open(path2))) + if (db_context_origin_warn(c1)) goto finish; + if (!(c2 = db_context_open(path2, 0))) + goto finish; + if (makepatch(c1, c2, args.inputs[0]) < 0) goto finish; @@ -248,15 +258,15 @@ static int do_foreach(int (*func) (struct syrep_db_context *c), int m) { static char saved_cwd[PATH_MAX]; if (args.local_temp_flag && isdirectory(args.inputs[i]) >= 1) { - const char *p = get_attached_filename(args.inputs[i], SYREP_TEMPDIR); + const char *p = get_snapshot_filename(args.inputs[i], SYREP_TEMPDIR); mkdir(p, 0777); setenv("TMPDIR", p, 1); } - if (!(path = strdup(get_attached_filename(args.inputs[i], SYREP_SNAPSHOTFILENAME)))) + if (!(path = strdup(get_snapshot_filename(args.inputs[i], SYREP_SNAPSHOTFILENAME)))) goto finish; - if (!(c = db_context_open(path))) + if (!(c = db_context_open(path, 0))) goto finish; if (args.inputs_num > 1) @@ -333,26 +343,26 @@ static int do_update(void) { } if (args.local_temp_flag) { - const char *p = get_attached_filename(args.inputs[i], SYREP_TEMPDIR); + const char *p = get_snapshot_filename(args.inputs[i], SYREP_TEMPDIR); mkdir(p, 0777); setenv("TMPDIR", p, 1); } - if (!(path = strdup(get_attached_filename(args.inputs[i], SYREP_SNAPSHOTFILENAME)))) + if (!(path = strdup(get_snapshot_filename(args.inputs[i], SYREP_SNAPSHOTFILENAME)))) goto finish; - if (!(c = db_context_open(path))) { - fprintf(stderr, "Initializing repository.\n"); - if (!(c = db_context_open(NULL))) - goto finish; - } + if (!(c = db_context_open(path, 1))) + goto finish; + + if (db_context_origin_warn(c)) + goto finish; if (!args.no_cache_flag) { const char *p; if (args.cache_given) cache = md_cache_open(args.cache_arg, args.ro_cache_flag); - else if ((p = get_attached_filename(args.inputs[i], SYREP_MDCACHEFILENAME))) + else if ((p = get_snapshot_filename(args.inputs[i], SYREP_MDCACHEFILENAME))) cache = md_cache_open(p, args.ro_cache_flag); } @@ -407,8 +417,48 @@ finish: return r; } +static int do_cleanup(void) { + int r = 1, i; + + if (args.inputs_num < 1) + fprintf(stderr, "WARNING: No repository specified!\n"); + + for (i = 0; i < args.inputs_num; i++) { + + if (isdirectory(args.inputs[i]) <= 0) { + fprintf(stderr, "%s is not a directory\n", args.inputs[i]); + goto finish; + } + + if (args.inputs_num > 1) + fprintf(stderr, "*** %s ***\n", args.inputs[i]); + + if (cleanup(args.inputs[i]) < 0) + goto finish; + + if (args.inputs_num > 1 && i < args.inputs_num-1) + fprintf(stderr, "\n"); + } + + r = 0; + +finish: + + return r; + +} + +static void sigint(int s) { + interrupted = 1; +} + int main(int argc, char *argv[]) { char *b; + struct sigaction sa; + + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = sigint; + sigaction(SIGINT, &sa, NULL); if ((b = strrchr(argv[0], '/'))) argv[0] = b+1; @@ -433,6 +483,8 @@ int main(int argc, char *argv[]) { return do_foreach(extract, 1); else if (args.makepatch_flag) return do_makepatch(); + else if (args.cleanup_flag) + return do_cleanup(); cmdline_parser_print_help(); |