<<< 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 giving
relatives paths.

This closes #2845.
---
 hcache.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/hcache.c b/hcache.c
index 95207b9..5f3c6b0 100644
--- a/hcache.c
+++ b/hcache.c
@@ -771,9 +771,28 @@ 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 != '/')
+  {
+    char *t = getwd (NULL);
+    char fix[_POSIX_PATH_MAX*2] = "";
+
+    if (t)
+    {
+      snprintf (fix, sizeof (fix), "%s/%s", t, folder);
+      p = safe_strdup (fix);
+      flen = mutt_strlen (p);
+      FREE(&t);
+    }
+  } 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