Merge branch 'jk/config-warn-on-inaccessible-paths'
When looking for $HOME/.gitconfig etc., it is OK if we cannot read them because they do not exist, but we did not diagnose existing files that we cannot read. * jk/config-warn-on-inaccessible-paths: warn_on_inaccessible(): a helper to warn on inaccessible paths attr: warn on inaccessible attribute files gitignore: report access errors of exclude files config: warn on inaccessible files
This commit is contained in:
commit
7fe136d78f
5
attr.c
5
attr.c
@ -352,8 +352,11 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
|
|||||||
char buf[2048];
|
char buf[2048];
|
||||||
int lineno = 0;
|
int lineno = 0;
|
||||||
|
|
||||||
if (!fp)
|
if (!fp) {
|
||||||
|
if (errno != ENOENT)
|
||||||
|
warn_on_inaccessible(path);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
res = xcalloc(1, sizeof(*res));
|
res = xcalloc(1, sizeof(*res));
|
||||||
while (fgets(buf, sizeof(buf), fp))
|
while (fgets(buf, sizeof(buf), fp))
|
||||||
handle_attr_line(res, buf, path, ++lineno, macro_ok);
|
handle_attr_line(res, buf, path, ++lineno, macro_ok);
|
||||||
|
@ -400,8 +400,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
|
|||||||
*/
|
*/
|
||||||
die("$HOME not set");
|
die("$HOME not set");
|
||||||
|
|
||||||
if (access(user_config, R_OK) &&
|
if (access_or_warn(user_config, R_OK) &&
|
||||||
xdg_config && !access(xdg_config, R_OK))
|
xdg_config && !access_or_warn(xdg_config, R_OK))
|
||||||
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
@ -60,7 +60,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc
|
|||||||
path = buf.buf;
|
path = buf.buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!access(path, R_OK)) {
|
if (!access_or_warn(path, R_OK)) {
|
||||||
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");
|
||||||
@ -939,23 +939,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(git_etc_gitconfig(), R_OK)) {
|
if (git_config_system() && !access_or_warn(git_etc_gitconfig(), R_OK)) {
|
||||||
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(xdg_config, R_OK)) {
|
if (xdg_config && !access_or_warn(xdg_config, R_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(user_config, R_OK)) {
|
if (user_config && !access_or_warn(user_config, R_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(repo_config, R_OK)) {
|
if (repo_config && !access_or_warn(repo_config, R_OK)) {
|
||||||
ret += git_config_from_file(fn, repo_config, data);
|
ret += git_config_from_file(fn, repo_config, data);
|
||||||
found += 1;
|
found += 1;
|
||||||
}
|
}
|
||||||
|
6
dir.c
6
dir.c
@ -397,6 +397,8 @@ int add_excludes_from_file_to_list(const char *fname,
|
|||||||
|
|
||||||
fd = open(fname, O_RDONLY);
|
fd = open(fname, O_RDONLY);
|
||||||
if (fd < 0 || fstat(fd, &st) < 0) {
|
if (fd < 0 || fstat(fd, &st) < 0) {
|
||||||
|
if (errno != ENOENT)
|
||||||
|
warn_on_inaccessible(fname);
|
||||||
if (0 <= fd)
|
if (0 <= fd)
|
||||||
close(fd);
|
close(fd);
|
||||||
if (!check_index ||
|
if (!check_index ||
|
||||||
@ -1311,9 +1313,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(path, R_OK))
|
if (!access_or_warn(path, R_OK))
|
||||||
add_excludes_from_file(dir, path);
|
add_excludes_from_file(dir, path);
|
||||||
if (excludes_file && !access(excludes_file, R_OK))
|
if (excludes_file && !access_or_warn(excludes_file, R_OK))
|
||||||
add_excludes_from_file(dir, excludes_file);
|
add_excludes_from_file(dir, excludes_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,6 +609,12 @@ int rmdir_or_warn(const char *path);
|
|||||||
*/
|
*/
|
||||||
int remove_or_warn(unsigned int mode, const char *path);
|
int remove_or_warn(unsigned int mode, const char *path);
|
||||||
|
|
||||||
|
/* Call access(2), but warn for any error besides ENOENT. */
|
||||||
|
int access_or_warn(const char *path, int mode);
|
||||||
|
|
||||||
|
/* Warn on an inaccessible file that ought to be accessible */
|
||||||
|
void warn_on_inaccessible(const char *path);
|
||||||
|
|
||||||
/* Get the passwd entry for the UID of the current process. */
|
/* Get the passwd entry for the UID of the current process. */
|
||||||
struct passwd *xgetpwuid_self(void);
|
struct passwd *xgetpwuid_self(void);
|
||||||
|
|
||||||
|
13
wrapper.c
13
wrapper.c
@ -403,6 +403,19 @@ int remove_or_warn(unsigned int mode, const char *file)
|
|||||||
return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file);
|
return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void warn_on_inaccessible(const char *path)
|
||||||
|
{
|
||||||
|
warning(_("unable to access '%s': %s"), path, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
int access_or_warn(const char *path, int mode)
|
||||||
|
{
|
||||||
|
int ret = access(path, mode);
|
||||||
|
if (ret && errno != ENOENT)
|
||||||
|
warn_on_inaccessible(path);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
struct passwd *xgetpwuid_self(void)
|
struct passwd *xgetpwuid_self(void)
|
||||||
{
|
{
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
Loading…
Reference in New Issue
Block a user