mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-02 18:57:46 +00:00
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.
This commit is contained in:
parent
5135ddaac6
commit
29aef94830
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user