From dfc4e2e0a83b4f275b5f0931fd1e8b5e5dcc03bf Mon Sep 17 00:00:00 2001 From: Marco Sirabella Date: Sun, 24 Jun 2018 17:45:39 -0400 Subject: [PATCH] Make path config variables relative --- init.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++---- mutt/file.c | 3 +-- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/init.c b/init.c index ac49cd4b0..d7ca2061d 100644 --- 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) diff --git a/mutt/file.c b/mutt/file.c index 6cd7313e6..a4fad5c54 100644 --- a/mutt/file.c +++ b/mutt/file.c @@ -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; -- 2.40.0