The 'tmp' param was always true.
Factor it out.
Thanks to @gahr for the idea/patch.
return fp;
}
-FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id, bool tmp)
+FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id)
{
char path[LONG_STRING];
struct stat sb;
if (!id || !*id || !bcache)
return NULL;
+ if (snprintf(path, sizeof(path), "%s%s%s", bcache->path, id, ".tmp") >= sizeof(path))
+ {
+ mutt_error(_("Path too long: %s%s%s"), bcache->path, id, ".tmp");
+ return NULL;
+ }
+
if (stat(bcache->path, &sb) == 0)
{
if (!S_ISDIR(sb.st_mode))
}
}
- snprintf(path, sizeof(path), "%s%s%s", bcache->path, id, tmp ? ".tmp" : "");
mutt_debug(3, "bcache: put: '%s'\n", path);
return safe_fopen(path, "w+");
* mutt_bcache_put - Create a file in the Body Cache
* @param bcache Body Cache from mutt_bcache_open()
* @param id Per-mailbox unique identifier for the message
- * @param tmp Returned FILE* is in a temporary location
- * If set, use mutt_bcache_commit to put it into place
* @retval FILE* on success
* @retval NULL on failure
+ *
+ * The returned FILE* is in a temporary location.
+ * Use mutt_bcache_commit to put it into place
*/
-FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id, bool tmp);
+FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id);
/**
* mutt_bcache_commit - Move a temporary file into the Body Cache
idata->bcache = msg_cache_open(idata);
snprintf(id, sizeof(id), "%u-%u", idata->uid_validity, HEADER_DATA(h)->uid);
- return mutt_bcache_put(idata->bcache, id, true);
+ return mutt_bcache_put(idata->bcache, id);
}
static int msg_cache_commit(struct ImapData *idata, struct Header *h)
/* create new cache file */
mutt_message(fetch_msg);
- msg->fp = mutt_bcache_put(nntp_data->bcache, article, true);
+ msg->fp = mutt_bcache_put(nntp_data->bcache, article);
if (!msg->fp)
{
mutt_mktemp(buf, sizeof(buf));
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, true)))
+ if (!(msg->fp = mutt_bcache_put(pop_data->bcache, h->data)))
{
/* no */
bcache = 0;