]> granicus.if.org Git - neomutt/commitdiff
Make path config variables relative 1274/head
authorMarco Sirabella <marco@sirabella.org>
Sun, 24 Jun 2018 21:45:39 +0000 (17:45 -0400)
committerRichard Russon <rich@flatcap.org>
Fri, 29 Jun 2018 10:23:34 +0000 (11:23 +0100)
init.c
mutt/file.c

diff --git a/init.c b/init.c
index ac49cd4b0606ee308a3996c9c8608f89691f48ac..d7ca2061dbc5e1cd3677a11de9e5957cd0cfbcd5 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1068,7 +1068,6 @@ static void restore_default(struct Option *p)
   switch (DTYPE(p->type))
   {
     case DT_STRING:
-    case DT_COMMAND:
       mutt_str_replace((char **) p->var, (char *) p->initial);
       break;
     case DT_MBTABLE:
@@ -1130,6 +1129,20 @@ static void restore_default(struct Option *p)
       *ptr = mutt_regex_create((const char *) p->initial, p->type, NULL);
       break;
     }
+    case DT_COMMAND:
+    {
+      char *init = (char *) p->initial;
+      FREE((char **) p->var);
+      if (init)
+      {
+        char command[LONG_STRING];
+        mutt_str_strfcpy(command, init, sizeof(command));
+        mutt_expand_path(command, sizeof(command));
+        *((char **) p->var) = mutt_str_strdup(command);
+      }
+
+      break;
+    }
   }
 
   if (p->flags & R_INDEX)
@@ -1168,11 +1181,11 @@ static void set_default(struct Option *p)
   switch (DTYPE(p->type))
   {
     case DT_STRING:
-    case DT_COMMAND:
       if (!p->initial && *((char **) p->var))
         p->initial = (unsigned long) mutt_str_strdup(*((char **) p->var));
       break;
     case DT_PATH:
+    case DT_COMMAND:
       if (!p->initial && *((char **) p->var))
       {
         char *cp = mutt_str_strdup(*((char **) p->var));
@@ -2153,6 +2166,13 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data,
           mutt_pretty_mailbox(tmp2, sizeof(tmp2));
           val = tmp2;
         }
+        else if (DTYPE(MuttVars[idx].type) == DT_COMMAND)
+        {
+          tmp2[0] = '\0';
+          mutt_str_strfcpy(tmp2, NONULL(*((char **) MuttVars[idx].var)), sizeof(tmp2));
+          mutt_pretty_mailbox(tmp2, sizeof(tmp2));
+          val = tmp2;
+        }
         else if (DTYPE(MuttVars[idx].type) == DT_MBTABLE)
         {
           struct MbTable *mbt = (*((struct MbTable **) MuttVars[idx].var));
@@ -2189,6 +2209,13 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data,
           char scratch[PATH_MAX];
           mutt_str_strfcpy(scratch, buf->data, sizeof(scratch));
           mutt_expand_path(scratch, sizeof(scratch));
+
+          struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
+          if (!mutt_file_to_absolute_path(scratch, np ? NONULL(np->data) : "./"))
+          {
+            mutt_error("Error: impossible to build path of '%s'.", scratch);
+          }
+
           if (mutt_str_strcmp(MuttVars[idx].name, "debug_file") == 0)
           {
             mutt_log_set_file(scratch, true);
@@ -2201,7 +2228,17 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data,
             *((char **) MuttVars[idx].var) = mutt_str_strdup(scratch);
           }
         }
-        else if ((idx >= 0) && ((DTYPE(MuttVars[idx].type) == DT_STRING) || (DTYPE(MuttVars[idx].type) == DT_COMMAND)))
+        else if ((idx >= 0) && (DTYPE(MuttVars[idx].type) == DT_COMMAND))
+        {
+          char scratch[PATH_MAX];
+          mutt_str_strfcpy(scratch, buf->data, sizeof(scratch));
+          mutt_expand_path(scratch, sizeof(scratch));
+          /* MuttVars[idx].var is already 'char**' (or some 'void**') or...
+           * so cast to 'void*' is okay */
+          FREE((void *) MuttVars[idx].var);
+          *((char **) MuttVars[idx].var) = mutt_str_strdup(scratch);
+        }
+        else if ((idx >= 0) && (DTYPE(MuttVars[idx].type) == DT_STRING))
         {
           if ((strstr(MuttVars[idx].name, "charset") &&
                check_charset(&MuttVars[idx], buf->data) < 0) |
@@ -4220,14 +4257,32 @@ int mutt_option_set(const struct Option *val, struct Buffer *err)
         char scratch[LONG_STRING];
         mutt_str_strfcpy(scratch, NONULL((const char *) val->var), sizeof(scratch));
         mutt_expand_path(scratch, sizeof(scratch));
+
+        struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
+        if (!mutt_file_to_absolute_path(scratch, np ? NONULL(np->data) : "./"))
+        {
+          mutt_error("Error: impossible to build path of '%s'.", scratch);
+        }
+
         /* MuttVars[idx].var is already 'char**' (or some 'void**') or...
          * so cast to 'void*' is okay */
         FREE((void *) MuttVars[idx].var);
         *((char **) MuttVars[idx].var) = mutt_str_strdup(scratch);
         break;
       }
-      case DT_STRING:
       case DT_COMMAND:
+      {
+        char scratch[LONG_STRING];
+        mutt_str_strfcpy(scratch, NONULL((const char *) val->var), sizeof(scratch));
+        mutt_expand_path(scratch, sizeof(scratch));
+
+        /* MuttVars[idx].var is already 'char**' (or some 'void**') or...
+         * so cast to 'void*' is okay */
+        FREE((void *) MuttVars[idx].var);
+        *((char **) MuttVars[idx].var) = mutt_str_strdup(scratch);
+        break;
+      }
+      case DT_STRING:
       {
         /* MuttVars[idx].var is already 'char**' (or some 'void**') or...
          * so cast to 'void*' is okay */
@@ -4455,7 +4510,8 @@ int var_to_string(int idx, char *val, size_t len)
 
   tmp[0] = '\0';
 
-  if ((DTYPE(MuttVars[idx].type) == DT_STRING) || (DTYPE(MuttVars[idx].type) == DT_PATH))
+  if ((DTYPE(MuttVars[idx].type) == DT_STRING) || (DTYPE(MuttVars[idx].type) == DT_PATH) ||
+      (DTYPE(MuttVars[idx].type) == DT_COMMAND))
   {
     mutt_str_strfcpy(tmp, NONULL(*((char **) MuttVars[idx].var)), sizeof(tmp));
     if (DTYPE(MuttVars[idx].type) == DT_PATH)
index 6cd7313e61b0a9c1cf6b78385e6be4f90e2eae5f..a4fad5c54b3633516b5edbafae6665a944b91281 100644 (file)
@@ -1328,8 +1328,7 @@ int mutt_file_to_absolute_path(char *path, const char *reference)
   mutt_str_strncat(abs_path, sizeof(abs_path), path, path_len > 0 ? path_len : 0);
 
   path = realpath(abs_path, path);
-
-  if (!path)
+  if (!path && (errno != ENOENT))
   {
     printf("Error: issue converting path to absolute (%s)", strerror(errno));
     return false;