Skip to content

Commit 8ffc331

Browse files
committed
Merge branch 'jk/config-warn-on-inaccessible-paths' into maint
The attribute system may be asked for a path that itself or its leading directories no longer exists in the working tree, and it is fine if we cannot open .gitattribute file in such a case. Failure to open per-directory .gitattributes with error status other than ENOENT and ENOTDIR should be diagnosed. * jk/config-warn-on-inaccessible-paths: attr: failure to open a .gitattributes file is OK with ENOTDIR 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
2 parents 01f7d7f + 8e950da commit 8ffc331

File tree

6 files changed

+34
-10
lines changed

6 files changed

+34
-10
lines changed

attr.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,11 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
352352
char buf[2048];
353353
int lineno = 0;
354354

355-
if (!fp)
355+
if (!fp) {
356+
if (errno != ENOENT && errno != ENOTDIR)
357+
warn_on_inaccessible(path);
356358
return NULL;
359+
}
357360
res = xcalloc(1, sizeof(*res));
358361
while (fgets(buf, sizeof(buf), fp))
359362
handle_attr_line(res, buf, path, ++lineno, macro_ok);

builtin/config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
400400
*/
401401
die("$HOME not set");
402402

403-
if (access(user_config, R_OK) &&
404-
xdg_config && !access(xdg_config, R_OK))
403+
if (access_or_warn(user_config, R_OK) &&
404+
xdg_config && !access_or_warn(xdg_config, R_OK))
405405
given_config_file = xdg_config;
406406
else
407407
given_config_file = user_config;

config.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc
6060
path = buf.buf;
6161
}
6262

63-
if (!access(path, R_OK)) {
63+
if (!access_or_warn(path, R_OK)) {
6464
if (++inc->depth > MAX_INCLUDE_DEPTH)
6565
die(include_depth_advice, MAX_INCLUDE_DEPTH, path,
6666
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)
939939

940940
home_config_paths(&user_config, &xdg_config, "config");
941941

942-
if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) {
942+
if (git_config_system() && !access_or_warn(git_etc_gitconfig(), R_OK)) {
943943
ret += git_config_from_file(fn, git_etc_gitconfig(),
944944
data);
945945
found += 1;
946946
}
947947

948-
if (xdg_config && !access(xdg_config, R_OK)) {
948+
if (xdg_config && !access_or_warn(xdg_config, R_OK)) {
949949
ret += git_config_from_file(fn, xdg_config, data);
950950
found += 1;
951951
}
952952

953-
if (user_config && !access(user_config, R_OK)) {
953+
if (user_config && !access_or_warn(user_config, R_OK)) {
954954
ret += git_config_from_file(fn, user_config, data);
955955
found += 1;
956956
}
957957

958-
if (repo_config && !access(repo_config, R_OK)) {
958+
if (repo_config && !access_or_warn(repo_config, R_OK)) {
959959
ret += git_config_from_file(fn, repo_config, data);
960960
found += 1;
961961
}

dir.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ int add_excludes_from_file_to_list(const char *fname,
397397

398398
fd = open(fname, O_RDONLY);
399399
if (fd < 0 || fstat(fd, &st) < 0) {
400+
if (errno != ENOENT)
401+
warn_on_inaccessible(fname);
400402
if (0 <= fd)
401403
close(fd);
402404
if (!check_index ||
@@ -1311,9 +1313,9 @@ void setup_standard_excludes(struct dir_struct *dir)
13111313
home_config_paths(NULL, &xdg_path, "ignore");
13121314
excludes_file = xdg_path;
13131315
}
1314-
if (!access(path, R_OK))
1316+
if (!access_or_warn(path, R_OK))
13151317
add_excludes_from_file(dir, path);
1316-
if (excludes_file && !access(excludes_file, R_OK))
1318+
if (excludes_file && !access_or_warn(excludes_file, R_OK))
13171319
add_excludes_from_file(dir, excludes_file);
13181320
}
13191321

git-compat-util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,12 @@ int rmdir_or_warn(const char *path);
604604
*/
605605
int remove_or_warn(unsigned int mode, const char *path);
606606

607+
/* Call access(2), but warn for any error besides ENOENT. */
608+
int access_or_warn(const char *path, int mode);
609+
610+
/* Warn on an inaccessible file that ought to be accessible */
611+
void warn_on_inaccessible(const char *path);
612+
607613
/* Get the passwd entry for the UID of the current process. */
608614
struct passwd *xgetpwuid_self(void);
609615

wrapper.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,19 @@ int remove_or_warn(unsigned int mode, const char *file)
403403
return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file);
404404
}
405405

406+
void warn_on_inaccessible(const char *path)
407+
{
408+
warning(_("unable to access '%s': %s"), path, strerror(errno));
409+
}
410+
411+
int access_or_warn(const char *path, int mode)
412+
{
413+
int ret = access(path, mode);
414+
if (ret && errno != ENOENT)
415+
warn_on_inaccessible(path);
416+
return ret;
417+
}
418+
406419
struct passwd *xgetpwuid_self(void)
407420
{
408421
struct passwd *pw;

0 commit comments

Comments
 (0)