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 --- git-compat-util.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'git-compat-util.h') diff --git a/git-compat-util.h b/git-compat-util.h index 35b095e8ae..5a520e2b73 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -604,6 +604,9 @@ 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); + /* Get the passwd entry for the UID of the current process. */ struct passwd *xgetpwuid_self(void); -- cgit v1.2.3 From 55b38a48e2a7ccfaaa7897a5fccb98327fa0e3c0 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 21 Aug 2012 14:52:07 -0700 Subject: warn_on_inaccessible(): a helper to warn on inaccessible paths The previous series introduced warnings to multiple places, but it could become tiring to see the warning on the same path over and over again during a single run of Git. Making just one function responsible for issuing this warning, we could later choose to keep track of which paths we issued a warning (it would involve a hash table of paths after running them through real_path() or something) in order to reduce noise. Right now we do not know if the noise reduction is necessary, but it still would be a good code reduction/sharing anyway. Signed-off-by: Junio C Hamano --- git-compat-util.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'git-compat-util.h') diff --git a/git-compat-util.h b/git-compat-util.h index 5a520e2b73..000042d793 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -607,6 +607,9 @@ 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); -- cgit v1.2.3