From 010485075c0889b12485cee0bcd974d505438bbe Mon Sep 17 00:00:00 2001 From: Rocco Rutte Date: Wed, 14 Mar 2007 12:53:49 -0700 Subject: [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 file changed, 14 insertions(+), 2 deletions(-) diff --git a/hcache.c b/hcache.c index 95207b9d..ef760d6a 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; -- 2.40.0