From e5c52c9898de5f829317729afc0416825531b0d5 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sat, 13 Oct 2012 17:03:07 -0700 Subject: config, gitignore: failure to access with ENOTDIR is ok The access_or_warn() function is used to check for optional configuration files like .gitconfig and .gitignore and warn when they are not accessible due to a configuration issue (e.g., bad permissions). It is not supposed to complain when a file is simply missing. Noticed on a system where ~/.config/git was a file --- when the new XDG_CONFIG_HOME support looks for ~/.config/git/config it should ignore ~/.config/git instead of printing irritating warnings: $ git status -s warning: unable to access '/home/jrn/.config/git/config': Not a directory warning: unable to access '/home/jrn/.config/git/config': Not a directory warning: unable to access '/home/jrn/.config/git/config': Not a directory warning: unable to access '/home/jrn/.config/git/config': Not a directory Compare v1.7.12.1~2^2 (attr:failure to open a .gitattributes file is OK with ENOTDIR, 2012-09-13). Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- wrapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wrapper.c') diff --git a/wrapper.c b/wrapper.c index 68739aaa3b..c1b919f335 100644 --- a/wrapper.c +++ b/wrapper.c @@ -411,7 +411,7 @@ void warn_on_inaccessible(const char *path) int access_or_warn(const char *path, int mode) { int ret = access(path, mode); - if (ret && errno != ENOENT) + if (ret && errno != ENOENT && errno != ENOTDIR) warn_on_inaccessible(path); return ret; } -- cgit v1.2.1 From 96b9e0e313604f77456906ce58db8f366e47f2ab Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sat, 13 Oct 2012 17:04:02 -0700 Subject: config: treat user and xdg config permission problems as errors Git reads multiple configuration files: settings come first from the system config file (typically /etc/gitconfig), then the xdg config file (typically ~/.config/git/config), then the user's dotfile (~/.gitconfig), then the repository configuration (.git/config). Git has always used access(2) to decide whether to use each file; as an unfortunate side effect, that means that if one of these files is unreadable (e.g., EPERM or EIO), git skips it. So if I use ~/.gitconfig to override some settings but make a mistake and give it the wrong permissions then I am subject to the settings the sysadmin chose for /etc/gitconfig. Better to error out and ask the user to correct the problem. This only affects the user and xdg config files, since the user presumably has enough access to fix their permissions. If the system config file is unreadable, the best we can do is to warn about it so the user knows to notify someone and get on with work in the meantime. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- wrapper.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'wrapper.c') diff --git a/wrapper.c b/wrapper.c index c1b919f335..7cbe96a0cc 100644 --- a/wrapper.c +++ b/wrapper.c @@ -416,6 +416,14 @@ int access_or_warn(const char *path, int mode) return ret; } +int access_or_die(const char *path, int mode) +{ + int ret = access(path, mode); + if (ret && errno != ENOENT && errno != ENOTDIR) + die_errno(_("unable to access '%s'"), path); + return ret; +} + struct passwd *xgetpwuid_self(void) { struct passwd *pw; -- cgit v1.2.1