summaryrefslogtreecommitdiffstats
path: root/src/package.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/package.c')
-rw-r--r--src/package.c28
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();