[PATCH] Header cache and slashes
So, I use maildirs, and the header caching sure is handy. But there's
a problem, in that it identifies mailboxes by their path, and when
tab-completing, there's often a stray '/' hanging at the end of the
path, so it gets treated as a different mailbox. This path appears to
correct it; I'm running an equivalent as I type this, and it seems to
work right. I'm only running the BDB code path, but it's a fairly
straightforward change in the others, so I don't expect troubles from
it.
Patch against CVS attached. Forgive me any code style deviations.
--
Matthew Fuller (MF4839) | fullermd@xxxxxxxxxxxxxxx
Systems/Network Administrator | http://www.over-yonder.net/~fullermd/
On the Internet, nobody can hear you scream.
Index: hcache.c
===================================================================
RCS file: /cvsroots/mutt/hcache.c,v
retrieving revision 3.16
diff -u -r3.16 hcache.c
--- hcache.c 21 Dec 2005 21:02:50 -0000 3.16
+++ hcache.c 17 Mar 2006 10:29:45 -0000
@@ -780,18 +780,26 @@
{
struct header_cache *h = safe_calloc(1, sizeof (HEADER_CACHE));
int flags = VL_OWRITER | VL_OCREAT;
+ char *ftmp, *ft2;
h->db = NULL;
- h->folder = safe_strdup(folder);
h->crc = generate_crc32();
+ ftmp = safe_strdup(folder);
+ ft2 = ftmp + strlen(ftmp) - 1;
+ while(ft2 > ftmp && *ft2=='/')
+ *ft2 = '\0';
+ h->folder = safe_strdup(ftmp);
+
if (!path || path[0] == '\0')
{
+ safe_free(&ftmp);
FREE(&h->folder);
FREE(&h);
return NULL;
}
- path = mutt_hcache_per_folder(path, folder);
+ path = mutt_hcache_per_folder(path, ftmp);
+ safe_free(&ftmp);
if (option(OPTHCACHECOMPRESS))
flags |= VL_OZCOMP;
@@ -846,19 +854,27 @@
mutt_hcache_open(const char *path, const char *folder)
{
struct header_cache *h = safe_calloc(1, sizeof (HEADER_CACHE));
+ char *ftmp, *ft2;
int pagesize = atoi(HeaderCachePageSize) ? atoi(HeaderCachePageSize) : 16384;
h->db = NULL;
- h->folder = safe_strdup(folder);
h->crc = generate_crc32();
+ ftmp = safe_strdup(folder);
+ ft2 = ftmp + strlen(ftmp) - 1;
+ while(ft2 > ftmp && *ft2=='/')
+ *ft2 = '\0';
+ h->folder = safe_strdup(ftmp);
+
if (!path || path[0] == '\0')
{
+ safe_free(&ftmp);
FREE(&h->folder);
FREE(&h);
return NULL;
}
- path = mutt_hcache_per_folder(path, folder);
+ path = mutt_hcache_per_folder(path, ftmp);
+ safe_free(&ftmp);
h->db = gdbm_open((char *) path, pagesize, GDBM_WRCREAT, 00600, NULL);
if (h->db)
@@ -935,6 +951,7 @@
u_int32_t createflags = DB_CREATE;
int ret;
struct header_cache *h = calloc(1, sizeof (HEADER_CACHE));
+ char *ftmp, *ft2;
int pagesize = atoi(HeaderCachePageSize);
h->crc = generate_crc32();
@@ -945,13 +962,19 @@
return NULL;
}
- path = mutt_hcache_per_folder(path, folder);
+ ftmp = safe_strdup(folder);
+ ft2 = ftmp + strlen(ftmp) - 1;
+ while(ft2 > ftmp && *ft2=='/')
+ *ft2 = '\0';
+
+ path = mutt_hcache_per_folder(path, ftmp);
snprintf(h->lockfile, _POSIX_PATH_MAX, "%s-lock-hack", path);
h->fd = open(h->lockfile, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
if (h->fd < 0)
{
+ safe_free(&ftmp);
FREE(&h);
return NULL;
}
@@ -959,6 +982,7 @@
if (mx_lock_file(h->lockfile, h->fd, 1, 0, 5))
{
close(h->fd);
+ safe_free(&ftmp);
FREE(&h);
return NULL;
}
@@ -968,6 +992,7 @@
{
mx_unlock_file(h->lockfile, h->fd, 0);
close(h->fd);
+ safe_free(&ftmp);
FREE(&h);
return NULL;
}
@@ -982,6 +1007,7 @@
h->env->close(h->env, 0);
mx_unlock_file(h->lockfile, h->fd, 0);
close(h->fd);
+ safe_free(&ftmp);
FREE(&h);
return NULL;
}
@@ -993,7 +1019,8 @@
h->db->set_pagesize(h->db, pagesize);
}
- ret = (*h->db->open)(h->db, NULL, path, folder, DB_BTREE, createflags, 0600);
+ ret = (*h->db->open)(h->db, NULL, path, ftmp, DB_BTREE, createflags, 0600);
+ safe_free(&ftmp);
if (ret)
{
h->db->close(h->db, 0);