Merge branch 'jk/config-warn-on-inaccessible-paths'
authorJunio C Hamano <gitster@pobox.com>
Fri, 7 Sep 2012 18:08:56 +0000 (11:08 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Sep 2012 18:08:56 +0000 (11:08 -0700)
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

1  2 
builtin/config.c
git-compat-util.h
diff --combined builtin/config.c
index ada6e1211462558f307dce6142b7b65d641c8e02,b0394efac9b7c257723b2a63be362138fd636e0f..442ccc2497c4e2e889d9de55359e36a1db07c1a4
@@@ -160,7 -160,7 +160,7 @@@ static int show_config(const char *key_
  
  static int get_value(const char *key_, const char *regex_)
  {
 -      int ret = -1;
 +      int ret = CONFIG_GENERIC_ERROR;
        char *global = NULL, *xdg = NULL, *repo_config = NULL;
        const char *system_wide = NULL, *local;
        struct config_include_data inc = CONFIG_INCLUDE_INIT;
                if (regcomp(key_regexp, key, REG_EXTENDED)) {
                        fprintf(stderr, "Invalid key pattern: %s\n", key_);
                        free(key);
 +                      ret = CONFIG_INVALID_PATTERN;
                        goto free_strings;
                }
        } else {
 -              if (git_config_parse_key(key_, &key, NULL))
 +              if (git_config_parse_key(key_, &key, NULL)) {
 +                      ret = CONFIG_INVALID_KEY;
                        goto free_strings;
 +              }
        }
  
        if (regex_) {
                regexp = (regex_t*)xmalloc(sizeof(regex_t));
                if (regcomp(regexp, regex_, REG_EXTENDED)) {
                        fprintf(stderr, "Invalid pattern: %s\n", regex_);
 +                      ret = CONFIG_INVALID_PATTERN;
                        goto free_strings;
                }
        }
@@@ -400,8 -396,8 +400,8 @@@ int cmd_config(int argc, const char **a
                         */
                        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;
diff --combined git-compat-util.h
index 34f040f59551c13b5e7c72bab12b8082b37a03ab,000042d79352b4a7bb789d60e5324af92f29871a..fd732d7243a9266302751189c32a57fd441a671d
  #define probe_utf8_pathname_composition(a,b)
  #endif
  
 +#ifdef MKDIR_WO_TRAILING_SLASH
 +#define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))
 +extern int compat_mkdir_wo_trailing_slash(const char*, mode_t);
 +#endif
 +
  #ifndef NO_LIBGEN_H
  #include <libgen.h>
  #else
@@@ -609,6 -604,12 +609,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);