From: Brendan Cully Date: Sun, 1 Apr 2007 01:50:39 +0000 (-0700) Subject: Add tmp flag to bcache_put, create bcache_commit. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d35432cb03bd5a43684079d90b1b82b5afb16551;p=neomutt Add tmp flag to bcache_put, create bcache_commit. --- diff --git a/ChangeLog b/ChangeLog index d2a844016..e874f1e21 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-03-31 16:07 -0700 Brendan Cully (bf208df92829) + + * imap/command.c, imap/imap.c: Allow IMAP FCC to reconnect if + append fails (closes: #890) + + * mh.c: Always set up data pointer in mh_read_dir, not just when + allocating context + 2007-03-30 21:26 -0700 Daniel Burrows (d5ab883ef90a) * hcache.c: Fix handling of DB4 hcache open failure. (closes: #2714) diff --git a/bcache.c b/bcache.c index fd52365c4..5b6d63ee6 100644 --- a/bcache.c +++ b/bcache.c @@ -131,7 +131,7 @@ FILE* mutt_bcache_get(body_cache_t *bcache, const char *id) return fp; } -FILE* mutt_bcache_put(body_cache_t *bcache, const char *id) +FILE* mutt_bcache_put(body_cache_t *bcache, const char *id, int tmp) { char path[_POSIX_PATH_MAX]; FILE* fp; @@ -141,9 +141,8 @@ FILE* mutt_bcache_put(body_cache_t *bcache, const char *id) if (!id || !*id || !bcache) return NULL; - path[0] = '\0'; - safe_strncat (path, sizeof (path), bcache->path, bcache->pathlen); - safe_strncat (path, sizeof (path), id, mutt_strlen (id)); + snprintf (path, sizeof (path), "%s%s%s", bcache->path, id, + tmp ? ".tmp" : ""); s = strchr (path + 1, '/'); while (!(fp = safe_fopen (path, "w+")) && errno == ENOENT && s) @@ -161,6 +160,15 @@ FILE* mutt_bcache_put(body_cache_t *bcache, const char *id) return fp; } +int mutt_bcache_commit(body_cache_t* bcache, const char* id) +{ + char tmpid[_POSIX_PATH_MAX]; + + snprintf (tmpid, sizeof (tmpid), "%s.tmp", id); + + return mutt_bcache_move (bcache, tmpid, id); +} + int mutt_bcache_move(body_cache_t* bcache, const char* id, const char* newid) { char path[_POSIX_PATH_MAX]; diff --git a/bcache.h b/bcache.h index d061a6ae7..35586e911 100644 --- a/bcache.h +++ b/bcache.h @@ -48,7 +48,10 @@ 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); +/* tmp: the returned FILE* is in a temporary location. + * if set, use mutt_bcache_commit to put it into place */ +FILE* mutt_bcache_put(body_cache_t *bcache, const char *id, int tmp); +int mutt_bcache_commit(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 a25c17386..3f3b23474 100644 --- a/imap/message.c +++ b/imap/message.c @@ -903,23 +903,21 @@ static FILE* msg_cache_put (IMAP_DATA* idata, HEADER* h) return NULL; idata->bcache = msg_cache_open (idata); - snprintf (id, sizeof (id), "%u-%u.tmp", idata->uid_validity, HEADER_DATA(h)->uid); - return mutt_bcache_put (idata->bcache, id); + snprintf (id, sizeof (id), "%u-%u", idata->uid_validity, HEADER_DATA(h)->uid); + return mutt_bcache_put (idata->bcache, id, 1); } 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); + snprintf (id, sizeof (id), "%u-%u", idata->uid_validity, HEADER_DATA(h)->uid); - return mutt_bcache_move (idata->bcache, id, newid); + return mutt_bcache_commit (idata->bcache, id); } int imap_cache_del (IMAP_DATA* idata, HEADER* h) diff --git a/pop.c b/pop.c index f84ec80c6..9fc4369c7 100644 --- a/pop.c +++ b/pop.c @@ -428,12 +428,12 @@ static void pop_clear_cache (POP_DATA *pop_data) } /* close POP mailbox */ -void pop_close_mailbox (CONTEXT *ctx) +int pop_close_mailbox (CONTEXT *ctx) { POP_DATA *pop_data = (POP_DATA *)ctx->data; if (!pop_data) - return; + return 0; pop_logout (ctx); @@ -450,7 +450,7 @@ void pop_close_mailbox (CONTEXT *ctx) mutt_bcache_close (&pop_data->bcache); - return; + return 0; } /* fetch message from POP server */ @@ -514,7 +514,7 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno) M_PROGRESS_SIZE, NetInc, h->content->length + h->content->offset - 1); /* see if we can put in body cache; use our cache as fallback */ - if (!(msg->fp = mutt_bcache_put (pop_data->bcache, h->data))) + if (!(msg->fp = mutt_bcache_put (pop_data->bcache, h->data, 1))) { /* no */ bcache = 0; @@ -538,9 +538,7 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno) /* if RETR failed (e.g. connection closed), be sure to remove either * the file in bcache or from POP's own cache since the next iteration * of the loop will re-attempt to put() the message */ - if (bcache) - mutt_bcache_del (pop_data->bcache, h->data); - else + if (!bcache) unlink (path); if (ret == -2) @@ -561,7 +559,9 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno) /* Update the header information. Previously, we only downloaded a * portion of the headers, those required for the main display. */ - if (!bcache) + if (bcache) + mutt_bcache_commit (pop_data->bcache, h->data); + else { cache->index = h->index; cache->path = safe_strdup (path); diff --git a/pop.h b/pop.h index 13bd1212f..efa6d9e3b 100644 --- a/pop.h +++ b/pop.h @@ -109,7 +109,7 @@ int pop_check_mailbox (CONTEXT *, int *); int pop_open_mailbox (CONTEXT *); int pop_sync_mailbox (CONTEXT *, int *); int pop_fetch_message (MESSAGE *, CONTEXT *, int); -void pop_close_mailbox (CONTEXT *); +int pop_close_mailbox (CONTEXT *); void pop_fetch_mail (void); #endif