diff options
-rw-r--r-- | attr.c | 5 | ||||
-rw-r--r-- | builtin/config.c | 4 | ||||
-rw-r--r-- | config.c | 10 | ||||
-rw-r--r-- | dir.c | 6 | ||||
-rw-r--r-- | git-compat-util.h | 6 | ||||
-rw-r--r-- | wrapper.c | 13 |
6 files changed, 34 insertions, 10 deletions
@@ -352,8 +352,11 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok) char buf[2048]; int lineno = 0; - if (!fp) + if (!fp) { + if (errno != ENOENT && errno != ENOTDIR) + warn_on_inaccessible(path); return NULL; + } res = xcalloc(1, sizeof(*res)); while (fgets(buf, sizeof(buf), fp)) handle_attr_line(res, buf, path, ++lineno, macro_ok); diff --git a/builtin/config.c b/builtin/config.c index ada6e12114..442ccc2497 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -400,8 +400,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) */ die("$HOME not set"); - if (access(user_config, R_OK) && - xdg_config && !access(xdg_config, R_OK)) + if (access_or_warn(user_config, R_OK) && + xdg_config && !access_or_warn(xdg_config, R_OK)) given_config_file = xdg_config; else given_config_file = user_config; @@ -60,7 +60,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc path = buf.buf; } - if (!access(path, R_OK)) { + if (!access_or_warn(path, R_OK)) { if (++inc->depth > MAX_INCLUDE_DEPTH) die(include_depth_advice, MAX_INCLUDE_DEPTH, path, 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"); - 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(), data); 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); 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); 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); found += 1; } @@ -397,6 +397,8 @@ int add_excludes_from_file_to_list(const char *fname, fd = open(fname, O_RDONLY); if (fd < 0 || fstat(fd, &st) < 0) { + if (errno != ENOENT) + warn_on_inaccessible(fname); if (0 <= fd) close(fd); if (!check_index || @@ -1311,9 +1313,9 @@ void setup_standard_excludes(struct dir_struct *dir) home_config_paths(NULL, &xdg_path, "ignore"); excludes_file = xdg_path; } - if (!access(path, R_OK)) + if (!access_or_warn(path, R_OK)) 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); } diff --git a/git-compat-util.h b/git-compat-util.h index 35b095e8ae..000042d793 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -604,6 +604,12 @@ int rmdir_or_warn(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. */ struct passwd *xgetpwuid_self(void); @@ -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); } +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 *pw; |