Commit 29aef948 by Edward Thomson

config, attrcache: don't fallback to dirs literally named `~`

The config and attrcache file reading code would attempt to load a file
in a home directory by expanding the `~` and looking for the file, using
`git_sysdir_find_global_file`.  If the file was not found, the error
handling would look for the literal path, eg `~/filename.txt`.

Use the new `git_config_expand_global_file` instead, which allows us to
get the path to the file separately, when the path is prefixed with
`~/`, and fail with a not found error without falling back to looking
for the literal path.
parent 5135ddaa
...@@ -290,14 +290,16 @@ static int attr_cache__lookup_path( ...@@ -290,14 +290,16 @@ static int attr_cache__lookup_path(
const char *cfgval = entry->value; const char *cfgval = entry->value;
/* expand leading ~/ as needed */ /* expand leading ~/ as needed */
if (cfgval && cfgval[0] == '~' && cfgval[1] == '/' && if (cfgval && cfgval[0] == '~' && cfgval[1] == '/') {
!git_sysdir_find_global_file(&buf, &cfgval[2])) if (! (error = git_sysdir_expand_global_file(&buf, &cfgval[2])))
*out = git_buf_detach(&buf); *out = git_buf_detach(&buf);
else if (cfgval) } else if (cfgval) {
*out = git__strdup(cfgval); *out = git__strdup(cfgval);
}
} }
else if (!git_sysdir_find_xdg_file(&buf, fallback)) else if (!git_sysdir_find_xdg_file(&buf, fallback)) {
*out = git_buf_detach(&buf); *out = git_buf_detach(&buf);
}
git_config_entry_free(entry); git_config_entry_free(entry);
git_buf_free(&buf); git_buf_free(&buf);
......
...@@ -1254,16 +1254,8 @@ static int strip_comments(char *line, int in_quotes) ...@@ -1254,16 +1254,8 @@ static int strip_comments(char *line, int in_quotes)
static int included_path(git_buf *out, const char *dir, const char *path) static int included_path(git_buf *out, const char *dir, const char *path)
{ {
/* From the user's home */ /* From the user's home */
int result; if (path[0] == '~' && path[1] == '/')
if (path[0] == '~' && path[1] == '/') { return git_sysdir_expand_global_file(out, &path[1]);
result = git_sysdir_find_global_file(out, &path[1]);
if (result == GIT_ENOTFOUND) {
git_buf_sets(out, &path[1]);
return 0;
}
return result;
}
return git_path_join_unrooted(out, path, dir, NULL); return git_path_join_unrooted(out, path, dir, NULL);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment