diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2017-03-23 11:59:06 +0000 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2017-03-23 12:12:39 +0000 |
commit | 29aef94830edb6231a0737cfca35233f9a95463f (patch) | |
tree | 4184da2670ba0d782c6507c40d63825b6b5b62c3 | |
parent | 5135ddaac6710cc0b4373764835dc6c519812bc4 (diff) | |
download | libgit2-29aef94830edb6231a0737cfca35233f9a95463f.tar.gz |
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.
-rw-r--r-- | src/attrcache.c | 12 | ||||
-rw-r--r-- | src/config_file.c | 12 |
2 files changed, 9 insertions, 15 deletions
diff --git a/src/attrcache.c b/src/attrcache.c index 4df14ee2c..54161894b 100644 --- a/src/attrcache.c +++ b/src/attrcache.c @@ -290,14 +290,16 @@ static int attr_cache__lookup_path( const char *cfgval = entry->value; /* expand leading ~/ as needed */ - if (cfgval && cfgval[0] == '~' && cfgval[1] == '/' && - !git_sysdir_find_global_file(&buf, &cfgval[2])) - *out = git_buf_detach(&buf); - else if (cfgval) + if (cfgval && cfgval[0] == '~' && cfgval[1] == '/') { + if (! (error = git_sysdir_expand_global_file(&buf, &cfgval[2]))) + *out = git_buf_detach(&buf); + } else if (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); + } git_config_entry_free(entry); git_buf_free(&buf); diff --git a/src/config_file.c b/src/config_file.c index 6ef80660a..5153f57d2 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -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) { /* From the user's home */ - int result; - if (path[0] == '~' && 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; - } + if (path[0] == '~' && path[1] == '/') + return git_sysdir_expand_global_file(out, &path[1]); return git_path_join_unrooted(out, path, dir, NULL); } |