From: Kevin McCarthy Date: Mon, 1 Aug 2016 01:42:07 +0000 (-0700) Subject: Move fflush and fsync to the mbox and mmdf commit_msg functions. X-Git-Tag: mutt-1-7-rel~19 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f33c66c210c5b8c73e095c8ff2a392ddae210f9;p=mutt 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. --- diff --git a/mbox.c b/mbox.c index 36dd81e7..1aabe9e5 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 7af22aae..e44ae5af 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 */