From c4c9439b4deb95d17e37970cf1da1c75d69dcb1b Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 31 Jul 2016 18:42:07 -0700 Subject: [PATCH] Move fflush and fsync to the mbox and mmdf commit_msg functions. The case statement in mx_commit_message() was previously distributed to the various ops->commit_msg() handlers, but the fflush and fsync were not. --- mbox.c | 18 ++++++++++++++---- mx.c | 12 +----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/mbox.c b/mbox.c index 36dd81e73..1aabe9e5e 100644 --- a/mbox.c +++ b/mbox.c @@ -463,20 +463,30 @@ static int mbox_close_message (CONTEXT *ctx, MESSAGE *msg) static int mbox_commit_message (CONTEXT *ctx, MESSAGE *msg) { - int r = fputc ('\n', msg->fp); + if (fputc ('\n', msg->fp) == EOF) + return -1; - if (r == EOF) + if ((fflush (msg->fp) == EOF) || + (fsync (fileno (msg->fp)) == -1)) + { + mutt_perror _("Can't write message"); return -1; + } return 0; } static int mmdf_commit_message (CONTEXT *ctx, MESSAGE *msg) { - int r = fputs (MMDF_SEP, msg->fp); + if (fputs (MMDF_SEP, msg->fp) == EOF) + return -1; - if (r == EOF) + if ((fflush (msg->fp) == EOF) || + (fsync (fileno (msg->fp)) == -1)) + { + mutt_perror _("Can't write message"); return -1; + } return 0; } diff --git a/mx.c b/mx.c index 7af22aaec..e44ae5afa 100644 --- a/mx.c +++ b/mx.c @@ -1423,7 +1423,6 @@ MESSAGE *mx_open_message (CONTEXT *ctx, int msgno) int mx_commit_message (MESSAGE *msg, CONTEXT *ctx) { struct mx_ops *ops = mx_get_ops (ctx->magic); - int r = 0; if (!ops || !ops->commit_msg) return -1; @@ -1435,16 +1434,7 @@ int mx_commit_message (MESSAGE *msg, CONTEXT *ctx) return -1; } - r = ops->commit_msg (ctx, msg); - - if (r == 0 && (ctx->magic == MUTT_MBOX || ctx->magic == MUTT_MMDF) - && (fflush (msg->fp) == EOF || fsync (fileno (msg->fp)) == -1)) - { - mutt_perror _("Can't write message"); - r = -1; - } - - return r; + return ops->commit_msg (ctx, msg); } /* close a pointer to a message */ -- 2.40.0