X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..e0765f8ab8243c097213733be0d4be2a31448b89:/bcache.c diff --git a/bcache.c b/bcache.c index ac07849..b61a207 100644 --- a/bcache.c +++ b/bcache.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 2006 Brendan Cully - * Copyright (C) 2006 Rocco Rutte + * Copyright (C) 2006-7 Brendan Cully + * Copyright (C) 2006, 2009 Rocco Rutte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,8 +42,9 @@ static int bcache_path(ACCOUNT *account, const char *mailbox, char *dst, size_t dstlen) { char host[STRING]; + char path[_POSIX_PATH_MAX]; ciss_url_t url; - size_t len; + int len; if (!account || !MessageCachedir || !*MessageCachedir || !dst || !dstlen) return -1; @@ -62,12 +63,14 @@ static int bcache_path(ACCOUNT *account, const char *mailbox, return -1; } - dprint (3, (debugfile, "bcache_path: URL: '%s'\n", host)); + mutt_encode_path (path, sizeof (path), NONULL (mailbox)); len = snprintf (dst, dstlen-1, "%s/%s%s%s", MessageCachedir, - host, NONULL(mailbox), - (mailbox && *mailbox && - mailbox[mutt_strlen(mailbox) - 1] == '/') ? "" : "/"); + host, path, + (*path && path[mutt_strlen (path) - 1] == '/') ? "" : "/"); + + dprint (3, (debugfile, "bcache_path: rc: %d, path: '%s'\n", len, dst)); + if (len < 0 || len >= dstlen-1) return -1; @@ -136,6 +139,13 @@ FILE* mutt_bcache_put(body_cache_t *bcache, const char *id, int tmp) snprintf (path, sizeof (path), "%s%s%s", bcache->path, id, tmp ? ".tmp" : ""); + if ((fp = safe_fopen (path, "w+"))) + goto out; + + if (errno == EEXIST) + /* clean up leftover tmp file */ + mutt_unlink (path); + s = strchr (path + 1, '/'); while (!(fp = safe_fopen (path, "w+")) && errno == ENOENT && s) { @@ -147,6 +157,7 @@ FILE* mutt_bcache_put(body_cache_t *bcache, const char *id, int tmp) s = strchr (s + 1, '/'); } + out: dprint (3, (debugfile, "bcache: put: '%s'\n", path)); return fp;