diff options
author | Lennart Poettering <lennart@poettering.net> | 2003-09-04 00:19:49 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2003-09-04 00:19:49 +0000 |
commit | dbcca8fecac7a6c4f04457b1dbb5682a5fadce58 (patch) | |
tree | 1b660d83bc44ded00c5842c17af558d558299bc7 | |
parent | 84044171f5aa29fbce94b5ed85345cd50a8ddf56 (diff) |
added atomicty
makepatch omits files existant on other other host under a different name
git-svn-id: file:///home/lennart/svn/public/syrep/trunk@21 07ea20a6-d2c5-0310-9e02-9ef735347d72
-rw-r--r-- | doc/todo.txt | 4 | ||||
-rw-r--r-- | src/makepatch.c | 24 | ||||
-rw-r--r-- | src/package.c | 28 | ||||
-rw-r--r-- | src/syrep.c | 4 | ||||
-rw-r--r-- | src/syrep.ggo | 1 |
5 files changed, 49 insertions, 12 deletions
diff --git a/doc/todo.txt b/doc/todo.txt index a88dc60..2196bfb 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -15,8 +15,8 @@ pre-0.1: - progress on package packing and unpacking DONE - replace path names by their hashes DONE - package.c: gzip support DONE -- package.c: atomicity -- fix makepatch to not include already existing files (by md5) +- package.c: atomicity DONE +- fix makepatch to not include already existing files DONE - better usage info on --help - documentation/man pages diff --git a/src/makepatch.c b/src/makepatch.c index 8bf1ee5..6e350f5 100644 --- a/src/makepatch.c +++ b/src/makepatch.c @@ -47,6 +47,8 @@ static int cb(DB *ddb, struct syrep_name *name, struct diff_entry *de, void *p) if (de->action != DIFF_COPY && de->action != DIFF_CONFLICT) return 0; + /* Check whether file exists in c1. If not, exit */ + if ((f = get_nrecno_by_name(cb_info->c1, name, &nrecno, 0)) < 0) return -1; @@ -57,19 +59,33 @@ static int cb(DB *ddb, struct syrep_name *name, struct diff_entry *de, void *p) if (!f) return 0; + /* Omit if the file exists in c2 under a different name */ + + if (!args.include_all_flag) { + + if ((f = get_current_nrecno_by_md(cb_info->c2, &md, NULL)) < 0) + return -1; + + if (f) + return 0; + } + + /* Ok, we add this file to the patch */ + fhex(md.digest, SYREP_DIGESTLENGTH, d); d[SYREP_DIGESTLENGTH*2] = 0; snprintf(path, sizeof(path), "%s/%s", cb_info->root, name->path); - fprintf(stderr, "Adding %s (%s) to patch.\n", name->path, d); + if (!package_get_item(cb_info->c1->package, d, 0)) { - /*** MISSING: DO NOT ADD FILES ALREADY EXISTING BY MD5 ***/ - - if (!package_get_item(cb_info->c1->package, d, 0)) + fprintf(stderr, "Adding %s (%s) to patch.\n", name->path, d); + if (package_add_file(cb_info->c1->package, d, path) < 0) return -1; + } + return 0; } diff --git a/src/package.c b/src/package.c index c684020..c78adc9 100644 --- a/src/package.c +++ b/src/package.c @@ -615,6 +615,7 @@ static int load_complete(struct package *p) { } int package_save(struct package *p, const char *fn) { + char path[PATH_MAX] = ""; int r = -1; struct package_item *i; uint32_t id; @@ -627,9 +628,20 @@ int package_save(struct package *p, const char *fn) { if (!fn || !strcmp(fn, "-")) p->write_fd = STDOUT_FILENO; - else if ((p->write_fd = open(fn, O_RDWR|O_TRUNC|O_CREAT, 0666)) < 0) { /* RDWR for mmap compatibility */ - fprintf(stderr, "open(\"%s\") XX: %s\n", fn, strerror(errno)); - goto finish; + else { + char hn[256]; + + if (gethostname(hn, sizeof(hn)) < 0) { + fprintf(stderr, "gethostname(): %s\n", strerror(errno)); + goto finish; + } + + snprintf(path, sizeof(path), "%s.%s.%u", fn, hn, getpid()); + + if ((p->write_fd = open(path, O_RDWR|O_TRUNC|O_CREAT, 0666)) < 0) { /* RDWR for mmap compatibility */ + fprintf(stderr, "open(\"%s\"): %s\n", fn, strerror(errno)); + goto finish; + } } id = args.compress_flag ? PACKAGE_FILEIDCOMPRESSED : PACKAGE_FILEID; @@ -669,8 +681,16 @@ finish: if (close_write_fd(p) < 0) r = -1; - if (r < 0 && fn) + if (!r) { unlink(fn); + if (link(path, fn) < 0) { + fprintf(stderr, "link(): %s\n", strerror(errno)); + r = -1; + } + } + + if (path[0]) + unlink(path); rotdash_hide(); diff --git a/src/syrep.c b/src/syrep.c index 25d939d..534c62b 100644 --- a/src/syrep.c +++ b/src/syrep.c @@ -461,11 +461,11 @@ static void free_args(void) { free(args.inputs); } +#include "package.h" + int main(int argc, char *argv[]) { struct sigaction sa; - fprintf(stderr, "Compiled with %i Bit off_t\n", sizeof(off_t)*8); - memset(&sa, 0, sizeof(sa)); sa.sa_handler = sigint; sigaction(SIGINT, &sa, NULL); diff --git a/src/syrep.ggo b/src/syrep.ggo index d14f5ea..fea530c 100644 --- a/src/syrep.ggo +++ b/src/syrep.ggo @@ -51,6 +51,7 @@ option "merge" - "Merge a snapshot or a repository into a repository" flag off option "makepatch" - "Make a patch against the specified repository" flag off option "output-file" o "makepatch: Write output to specified file instead of STDOUT" string no + option "include-all" - "makepatch: Include files in patch which do exist on the other side under a different name" flag off option "extract" - "Extract the context of a snapshot or patch" flag off option "output-directory" D "extract: Write output to specified directory" string no |