From ba8bd8300a544959159f6bd3a7e03ac54f85ea3a Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 21 Aug 2012 02:10:59 -0400 Subject: config: warn on inaccessible files Before reading a config file, we check "!access(path, R_OK)" to make sure that the file exists and is readable. If it's not, then we silently ignore it. For the case of ENOENT, this is fine, as the presence of the file is optional. For other cases, though, it may indicate a configuration error (e.g., not having permissions to read the file). Let's print a warning in these cases to let the user know. Signed-off-by: Jeff King 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 b5e33e49c7..b40c7e73da 100644 --- a/wrapper.c +++ b/wrapper.c @@ -403,6 +403,14 @@ int remove_or_warn(unsigned int mode, const char *file) return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file); } +int access_or_warn(const char *path, int mode) +{ + int ret = access(path, mode); + if (ret && errno != ENOENT) + warning(_("unable to access '%s': %s"), path, strerror(errno)); + return ret; +} + struct passwd *xgetpwuid_self(void) { struct passwd *pw; -- cgit v1.2.1