[PATCH] Ignore trailing slashes for folder names with header cache
Hi,
with maildir mutt's tab-completion is not optimal as it automatically
adds a trailing slash. This leads to different md5 sums (in case one db
file per folder is used) and to different keys for the messages.
The latter makes it a little more complicated to ignore the slash
because the same md5 sum isn't enough because the key is different.
Attached is a patch which should work for all hcache modules.
The patch doesn't really conform to mutt coding style as does hcache.c
in many more places...
bye, Rocco
--
:wq!
diff --git a/hcache.c b/hcache.c
index 0974600..db80da1 100644
--- a/hcache.c
+++ b/hcache.c
@@ -769,14 +769,25 @@ #elif HAVE_GDBM
#endif
}
+static char* get_foldername(const char *folder) {
+ size_t flen = mutt_strlen (folder);
+ char* p = safe_strdup(folder);
+
+ if (flen > 0 && folder[flen-1] == '/')
+ p[flen-1] = '\0';
+
+ return p;
+}
+
#if HAVE_QDBM
header_cache_t *
mutt_hcache_open(const char *path, const char *folder)
{
struct header_cache *h = safe_calloc(1, sizeof (HEADER_CACHE));
int flags = VL_OWRITER | VL_OCREAT;
+
h->db = NULL;
- h->folder = safe_strdup(folder);
+ h->folder = get_foldername(folder);
h->crc = generate_crc32();
if (!path || path[0] == '\0')
@@ -786,7 +797,7 @@ mutt_hcache_open(const char *path, const
return NULL;
}
- path = mutt_hcache_per_folder(path, folder);
+ path = mutt_hcache_per_folder(path, h->folder);
if (option(OPTHCACHECOMPRESS))
flags |= VL_OZCOMP;
@@ -839,8 +850,9 @@ mutt_hcache_open(const char *path, const
{
struct header_cache *h = safe_calloc(1, sizeof (HEADER_CACHE));
int pagesize = atoi(HeaderCachePageSize) ? atoi(HeaderCachePageSize) : 16384;
+
h->db = NULL;
- h->folder = safe_strdup(folder);
+ h->folder = get_foldername(folder);
h->crc = generate_crc32();
if (!path || path[0] == '\0')
@@ -850,7 +862,7 @@ mutt_hcache_open(const char *path, const
return NULL;
}
- path = mutt_hcache_per_folder(path, folder);
+ path = mutt_hcache_per_folder(path, h->folder);
h->db = gdbm_open((char *) path, pagesize, GDBM_WRCREAT, 00600, NULL);
if (h->db)
@@ -925,6 +937,7 @@ mutt_hcache_open(const char *path, const
int ret;
struct header_cache *h = calloc(1, sizeof (HEADER_CACHE));
int pagesize = atoi(HeaderCachePageSize);
+ char* tmp;
h->crc = generate_crc32();
@@ -934,9 +947,10 @@ mutt_hcache_open(const char *path, const
return NULL;
}
- path = mutt_hcache_per_folder(path, folder);
-
+ tmp = get_foldername (folder);
+ path = mutt_hcache_per_folder(path, tmp);
snprintf(h->lockfile, _POSIX_PATH_MAX, "%s-lock-hack", path);
+ FREE(&tmp);
h->fd = open(h->lockfile, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
if (h->fd < 0)