fname = NULL;
o_stream_unref(output);
- if (close(fd) < 0)
+ /* FIXME: when saving multiple messages, we could get better
+ performance if we left the fd open and fsync()ed it later */
+ if (fsync(fd) < 0) {
+ mail_storage_set_critical(ibox->box.storage,
+ "fsync() failed for %s: %m", path);
fname = NULL;
+ }
+ if (close(fd) < 0) {
+ mail_storage_set_critical(ibox->box.storage,
+ "close() failed for %s: %m", path);
+ fname = NULL;
+ }
if (fname == NULL)
(void)unlink(path);
syscall_error(ctx, "ftruncate()");
failed = TRUE;
}
+ } else {
+ if (fdatasync(ctx->ibox->index->mbox_fd) < 0) {
+ syscall_error(ctx, "fsync()");
+ failed = TRUE;
+ }
}
i_free(ctx);