Merge branch 'jn/config-ignore-inaccessible'
When $HOME is misconfigured to point at an unreadable directory, we used to complain and die. This loosens the check. * jn/config-ignore-inaccessible: config: allow inaccessible configuration under $HOME
This commit is contained in:
commit
7ebb906ddd
@ -379,8 +379,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
|
|||||||
*/
|
*/
|
||||||
die("$HOME not set");
|
die("$HOME not set");
|
||||||
|
|
||||||
if (access_or_warn(user_config, R_OK) &&
|
if (access_or_warn(user_config, R_OK, 0) &&
|
||||||
xdg_config && !access_or_warn(xdg_config, R_OK))
|
xdg_config && !access_or_warn(xdg_config, R_OK, 0))
|
||||||
given_config_file = xdg_config;
|
given_config_file = xdg_config;
|
||||||
else
|
else
|
||||||
given_config_file = user_config;
|
given_config_file = user_config;
|
||||||
|
10
config.c
10
config.c
@ -58,7 +58,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc
|
|||||||
path = buf.buf;
|
path = buf.buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!access_or_die(path, R_OK)) {
|
if (!access_or_die(path, R_OK, 0)) {
|
||||||
if (++inc->depth > MAX_INCLUDE_DEPTH)
|
if (++inc->depth > MAX_INCLUDE_DEPTH)
|
||||||
die(include_depth_advice, MAX_INCLUDE_DEPTH, path,
|
die(include_depth_advice, MAX_INCLUDE_DEPTH, path,
|
||||||
cf && cf->name ? cf->name : "the command line");
|
cf && cf->name ? cf->name : "the command line");
|
||||||
@ -954,23 +954,23 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
|
|||||||
|
|
||||||
home_config_paths(&user_config, &xdg_config, "config");
|
home_config_paths(&user_config, &xdg_config, "config");
|
||||||
|
|
||||||
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK)) {
|
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0)) {
|
||||||
ret += git_config_from_file(fn, git_etc_gitconfig(),
|
ret += git_config_from_file(fn, git_etc_gitconfig(),
|
||||||
data);
|
data);
|
||||||
found += 1;
|
found += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xdg_config && !access_or_die(xdg_config, R_OK)) {
|
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK)) {
|
||||||
ret += git_config_from_file(fn, xdg_config, data);
|
ret += git_config_from_file(fn, xdg_config, data);
|
||||||
found += 1;
|
found += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user_config && !access_or_die(user_config, R_OK)) {
|
if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK)) {
|
||||||
ret += git_config_from_file(fn, user_config, data);
|
ret += git_config_from_file(fn, user_config, data);
|
||||||
found += 1;
|
found += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (repo_config && !access_or_die(repo_config, R_OK)) {
|
if (repo_config && !access_or_die(repo_config, R_OK, 0)) {
|
||||||
ret += git_config_from_file(fn, repo_config, data);
|
ret += git_config_from_file(fn, repo_config, data);
|
||||||
found += 1;
|
found += 1;
|
||||||
}
|
}
|
||||||
|
4
dir.c
4
dir.c
@ -1542,9 +1542,9 @@ void setup_standard_excludes(struct dir_struct *dir)
|
|||||||
home_config_paths(NULL, &xdg_path, "ignore");
|
home_config_paths(NULL, &xdg_path, "ignore");
|
||||||
excludes_file = xdg_path;
|
excludes_file = xdg_path;
|
||||||
}
|
}
|
||||||
if (!access_or_warn(path, R_OK))
|
if (!access_or_warn(path, R_OK, 0))
|
||||||
add_excludes_from_file(dir, path);
|
add_excludes_from_file(dir, path);
|
||||||
if (excludes_file && !access_or_warn(excludes_file, R_OK))
|
if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
|
||||||
add_excludes_from_file(dir, excludes_file);
|
add_excludes_from_file(dir, excludes_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -692,8 +692,9 @@ int remove_or_warn(unsigned int mode, const char *path);
|
|||||||
* Call access(2), but warn for any error except "missing file"
|
* Call access(2), but warn for any error except "missing file"
|
||||||
* (ENOENT or ENOTDIR).
|
* (ENOENT or ENOTDIR).
|
||||||
*/
|
*/
|
||||||
int access_or_warn(const char *path, int mode);
|
#define ACCESS_EACCES_OK (1U << 0)
|
||||||
int access_or_die(const char *path, int mode);
|
int access_or_warn(const char *path, int mode, unsigned flag);
|
||||||
|
int access_or_die(const char *path, int mode, unsigned flag);
|
||||||
|
|
||||||
/* Warn on an inaccessible file that ought to be accessible */
|
/* Warn on an inaccessible file that ought to be accessible */
|
||||||
void warn_on_inaccessible(const char *path);
|
void warn_on_inaccessible(const char *path);
|
||||||
|
14
wrapper.c
14
wrapper.c
@ -408,18 +408,24 @@ void warn_on_inaccessible(const char *path)
|
|||||||
warning(_("unable to access '%s': %s"), path, strerror(errno));
|
warning(_("unable to access '%s': %s"), path, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
int access_or_warn(const char *path, int mode)
|
static int access_error_is_ok(int err, unsigned flag)
|
||||||
|
{
|
||||||
|
return err == ENOENT || err == ENOTDIR ||
|
||||||
|
((flag & ACCESS_EACCES_OK) && err == EACCES);
|
||||||
|
}
|
||||||
|
|
||||||
|
int access_or_warn(const char *path, int mode, unsigned flag)
|
||||||
{
|
{
|
||||||
int ret = access(path, mode);
|
int ret = access(path, mode);
|
||||||
if (ret && errno != ENOENT && errno != ENOTDIR)
|
if (ret && !access_error_is_ok(errno, flag))
|
||||||
warn_on_inaccessible(path);
|
warn_on_inaccessible(path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int access_or_die(const char *path, int mode)
|
int access_or_die(const char *path, int mode, unsigned flag)
|
||||||
{
|
{
|
||||||
int ret = access(path, mode);
|
int ret = access(path, mode);
|
||||||
if (ret && errno != ENOENT && errno != ENOTDIR)
|
if (ret && !access_error_is_ok(errno, flag))
|
||||||
die_errno(_("unable to access '%s'"), path);
|
die_errno(_("unable to access '%s'"), path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user