Skip to content

Commit

Permalink
warn_on_inaccessible(): a helper to warn on inaccessible paths
Browse files Browse the repository at this point in the history
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 <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Aug 21, 2012
1 parent 11e50b2 commit 55b38a4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)

if (!fp) {
if (errno != ENOENT)
warning(_("unable to access '%s': %s"), path, strerror(errno));
warn_on_inaccessible(path);
return NULL;
}
res = xcalloc(1, sizeof(*res));
Expand Down
2 changes: 1 addition & 1 deletion dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ int add_excludes_from_file_to_list(const char *fname,
fd = open(fname, O_RDONLY);
if (fd < 0 || fstat(fd, &st) < 0) {
if (errno != ENOENT)
warning(_("unable to access '%s': %s"), fname, strerror(errno));
warn_on_inaccessible(fname);
if (0 <= fd)
close(fd);
if (!check_index ||
Expand Down
3 changes: 3 additions & 0 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,16 @@ int remove_or_warn(unsigned int mode, const char *file)
return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file);
}

void warn_on_inaccessible(const char *path)
{
warning(_("unable to access '%s': %s"), path, strerror(errno));
}

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));
warn_on_inaccessible(path);
return ret;
}

Expand Down

0 comments on commit 55b38a4

Please sign in to comment.