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 /src/package.c | |
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
Diffstat (limited to 'src/package.c')
-rw-r--r-- | src/package.c | 28 |
1 files changed, 24 insertions, 4 deletions
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(); |