From 9ee15bbab6a96917ccbb587bc9a86bf930564f4a Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Wed, 29 Oct 2008 13:21:57 +0100 Subject: [PATCH] Fixed fb-atomic. --- ucw/fb-atomic.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ucw/fb-atomic.c b/ucw/fb-atomic.c index 2283cee5..1b4a07bb 100644 --- a/ucw/fb-atomic.c +++ b/ucw/fb-atomic.c @@ -11,6 +11,7 @@ #include "ucw/fastbuf.h" #include "ucw/lfs.h" #include "ucw/conf.h" +#include "ucw/trans.h" #include #include @@ -53,9 +54,9 @@ fbatomic_internal_write(struct fastbuf *f) ASSERT(af->record_len < 0 || !(size % af->record_len)); int res = write(af->fd, f->buffer, size); if (res < 0) - die("Error writing %s: %m", f->name); + bthrow(f, "fb.write", "Error writing %s: %m", f->name); if (res != size) - die("Unexpected partial write to %s: written only %d bytes of %d", f->name, res, size); + bthrow(f, "fb.write", "Unexpected partial write to %s: written only %d bytes of %d", f->name, res, size); f->bptr = f->buffer; } } @@ -86,7 +87,8 @@ static void fbatomic_close(struct fastbuf *f) { struct fb_atomic_file *af = FB_ATOMIC(f)->af; - fbatomic_internal_write(f); /* Need to flush explicitly, because the file can be locked */ + if (!(f->flags & FB_DEAD)) + fbatomic_internal_write(f); /* Need to flush explicitly, because the file can be locked */ if (!--af->use_count) { close(af->fd); @@ -109,9 +111,11 @@ fbatomic_open(const char *name, struct fastbuf *master, uns bufsize, int record_ } else { + int fd = ucw_open(name, O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, 0666); + if (fd < 0) + trans_throw("fb.open", NULL, "Cannot create %s: %m", name); af = xmalloc_zero(sizeof(*af) + strlen(name)); - if ((af->fd = ucw_open(name, O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, 0666)) < 0) - die("Cannot create %s: %m", name); + af->fd = fd; af->use_count = 1; af->record_len = record_len; af->locked = (record_len < 0); -- 2.39.2