Commit d037dbdd authored by Brendan Cully's avatar Brendan Cully

fflush before fsync and close. Closes #2962 again.

parent dd364fe7
2008-06-25 23:13 -0700 Brendan Cully <[email protected]> (d2134eced31b)
2008-06-26 00:18 -0700 Brendan Cully <[email protected]> (5d46ad49d04a)
* mh.c: fsync maildir/mh messages on commit. Closes #2962.
2008-06-25 23:40 -0700 Brendan Cully <[email protected]> (32374c911c6c)
* smime.c: Check S/MIME signing ID exists before attempting to use
it. Closes #3069. Also make (s)ign automatically ask for a key if
no default is defined.
* init.h: Make $move default to no instead of ask-no. Closes #2945.
......
......@@ -209,6 +209,25 @@ int safe_fclose (FILE **f)
return r;
}
int safe_fsync_close (FILE **f)
{
int r = 0;
if (*f)
{
if (fflush (*f) || fsync (fileno (*f)))
{
r = -1;
fclose (*f);
}
else
r = fclose(*f);
*f = NULL;
}
return r;
}
char *safe_strdup (const char *s)
{
char *p;
......
......@@ -170,6 +170,7 @@ int safe_open (const char *, int);
int safe_rename (const char *, const char *);
int safe_symlink (const char *, const char *);
int safe_fclose (FILE **);
int safe_fsync_close (FILE **);
size_t mutt_quote_filename (char *, size_t, const char *);
size_t mutt_strlen (const char *);
......
......@@ -1311,13 +1311,11 @@ int maildir_commit_message (CONTEXT * ctx, MESSAGE * msg, HEADER * hdr)
char full[_POSIX_PATH_MAX];
char *s;
if (msg->fp && fsync(fileno(msg->fp)) < 0)
if (safe_fsync_close (&msg->fp))
{
mutt_perror("Could not flush message to disk");
mutt_perror (_("Could not flush message to disk"));
return -1;
}
if (safe_fclose (&msg->fp) != 0)
return -1;
/* extract the subdir */
s = strrchr (msg->path, '/') + 1;
......@@ -1391,13 +1389,11 @@ static int _mh_commit_message (CONTEXT * ctx, MESSAGE * msg, HEADER * hdr,
char path[_POSIX_PATH_MAX];
char tmp[16];
if (msg->fp && fsync(fileno(msg->fp)) < 0)
if (safe_fsync_close (&msg->fp))
{
mutt_perror("Could not flush message to disk");
mutt_perror (_("Could not flush message to disk"));
return -1;
}
if (safe_fclose (&msg->fp) != 0)
return -1;
if ((dirp = opendir (ctx->path)) == NULL)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment