From 61e8e17e275e86fec57ed1b5f2d07b8375688db4 Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Thu, 29 Mar 2007 10:30:15 -0700 Subject: [PATCH] Make message cache write to temporary location until file is complete. Previously mutt trusted the cache file even when it was incomplete, causing permanently incorrect message display if the fetch was interrupted for some reason. --- ChangeLog | 9 +++++++++ bcache.c | 16 ++++++++++++++++ bcache.h | 1 + imap/message.c | 22 ++++++++++++++++++++-- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b3d181b5..3dea57d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-03-28 09:43 +0200 Thomas Roessler (25cbd5588d35) + + * alias.c: Fix debug message for mutt_adr_is_user + +2007-03-23 10:32 -0700 Brendan Cully (888a57a2b5f2) + + * imap/browse.c: Reset list.name before each list response in + folder browser + 2007-03-22 14:36 +0100 Thomas Roessler (68cfab02b411) * curs_main.c: Fix update_index(). diff --git a/bcache.c b/bcache.c index b6489bf9..fd52365c 100644 --- a/bcache.c +++ b/bcache.c @@ -161,6 +161,22 @@ FILE* mutt_bcache_put(body_cache_t *bcache, const char *id) return fp; } +int mutt_bcache_move(body_cache_t* bcache, const char* id, const char* newid) +{ + char path[_POSIX_PATH_MAX]; + char newpath[_POSIX_PATH_MAX]; + + if (!bcache || !id || !*id || !newid || !*newid) + return -1; + + snprintf (path, sizeof (path), "%s%s", bcache->path, id); + snprintf (newpath, sizeof (newpath), "%s%s", bcache->path, newid); + + dprint (3, (debugfile, "bcache: mv: '%s' '%s'\n", path, newpath)); + + return rename (path, newpath); +} + int mutt_bcache_del(body_cache_t *bcache, const char *id) { char path[_POSIX_PATH_MAX]; diff --git a/bcache.h b/bcache.h index f7728a54..d061a6ae 100644 --- a/bcache.h +++ b/bcache.h @@ -49,6 +49,7 @@ void mutt_bcache_close (body_cache_t **bcache); FILE* mutt_bcache_get(body_cache_t *bcache, const char *id); FILE* mutt_bcache_put(body_cache_t *bcache, const char *id); +int mutt_bcache_move(body_cache_t *bcache, const char *id, const char *newid); int mutt_bcache_del(body_cache_t *bcache, const char *id); int mutt_bcache_exists(body_cache_t *bcache, const char *id); diff --git a/imap/message.c b/imap/message.c index a7a3fcac..a25c1738 100644 --- a/imap/message.c +++ b/imap/message.c @@ -45,6 +45,7 @@ static FILE* msg_cache_get (IMAP_DATA* idata, HEADER* h); static FILE* msg_cache_put (IMAP_DATA* idata, HEADER* h); +static int msg_cache_commit (IMAP_DATA* idata, HEADER* h); static void flush_buffer(char* buf, size_t* len, CONNECTION* conn); static int msg_fetch_header (CONTEXT* ctx, IMAP_HEADER* h, char* buf, @@ -500,7 +501,9 @@ int imap_fetch_message (MESSAGE *msg, CONTEXT *ctx, int msgno) if (!fetched || !imap_code (idata->buf)) goto bail; -parsemsg: + msg_cache_commit (idata, h); + + parsemsg: /* Update the header information. Previously, we only downloaded a * portion of the headers, those required for the main display. */ @@ -900,10 +903,25 @@ static FILE* msg_cache_put (IMAP_DATA* idata, HEADER* h) return NULL; idata->bcache = msg_cache_open (idata); - snprintf (id, sizeof (id), "%u-%u", idata->uid_validity, HEADER_DATA(h)->uid); + snprintf (id, sizeof (id), "%u-%u.tmp", idata->uid_validity, HEADER_DATA(h)->uid); return mutt_bcache_put (idata->bcache, id); } +static int msg_cache_commit (IMAP_DATA* idata, HEADER* h) +{ + char id[_POSIX_PATH_MAX]; + char newid[_POSIX_PATH_MAX]; + + if (!idata || !h) + return -1; + + idata->bcache = msg_cache_open (idata); + snprintf (id, sizeof (id), "%u-%u.tmp", idata->uid_validity, HEADER_DATA(h)->uid); + snprintf (newid, sizeof (newid), "%u-%u", idata->uid_validity, HEADER_DATA(h)->uid); + + return mutt_bcache_move (idata->bcache, id, newid); +} + int imap_cache_del (IMAP_DATA* idata, HEADER* h) { char id[_POSIX_PATH_MAX]; -- 2.50.1