<<< Date Index >>>     <<< Thread Index >>>

[PATCH] hcache: prepend current dir to path for local folders



If a folder is local (i.e. stat() succeeds), prepend the current working
directory if necessary to always fully qualify the path. Otherwise we
may end up using different cache files for the same folder when given
relative paths. This closes #2845.
---
 hcache.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/hcache.c b/hcache.c
index 95207b9..ef760d6 100644
--- a/hcache.c
+++ b/hcache.c
@@ -771,9 +771,21 @@ mutt_hcache_store_raw (header_cache_t* h, const char* 
filename, void* data,
 
 static char* get_foldername(const char *folder) {
   size_t flen = mutt_strlen (folder);
-  char* p = safe_strdup(folder);
+  char *p = NULL;
+  struct stat st;
 
-  if (flen > 0 && folder[flen-1] == '/')
+  /* if the folder exists and doesn't start with /,
+   * prepend cwd to always use the same hcache per folder */
+  if (stat (folder, &st) == 0 && flen > 0 && *folder != '/')
+  {
+    p = safe_malloc (_POSIX_PATH_MAX+1);
+    if (!realpath (folder, p))
+      mutt_str_replace (&p, folder);
+  } else
+    p = safe_strdup (folder);
+
+  /* make sure we have no trailing / as added by tab completion */
+  if (flen > 0 && p[flen-1] == '/')
     p[flen-1] = '\0';
 
   return p;
-- 
1.5.0.3.920.g51d7f