Skip to content

Commit 55b38a4

Browse files
committed
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 <[email protected]>
1 parent 11e50b2 commit 55b38a4

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

attr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
354354

355355
if (!fp) {
356356
if (errno != ENOENT)
357-
warning(_("unable to access '%s': %s"), path, strerror(errno));
357+
warn_on_inaccessible(path);
358358
return NULL;
359359
}
360360
res = xcalloc(1, sizeof(*res));

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ int add_excludes_from_file_to_list(const char *fname,
398398
fd = open(fname, O_RDONLY);
399399
if (fd < 0 || fstat(fd, &st) < 0) {
400400
if (errno != ENOENT)
401-
warning(_("unable to access '%s': %s"), fname, strerror(errno));
401+
warn_on_inaccessible(fname);
402402
if (0 <= fd)
403403
close(fd);
404404
if (!check_index ||

git-compat-util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ int remove_or_warn(unsigned int mode, const char *path);
607607
/* Call access(2), but warn for any error besides ENOENT. */
608608
int access_or_warn(const char *path, int mode);
609609

610+
/* Warn on an inaccessible file that ought to be accessible */
611+
void warn_on_inaccessible(const char *path);
612+
610613
/* Get the passwd entry for the UID of the current process. */
611614
struct passwd *xgetpwuid_self(void);
612615

wrapper.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,16 @@ 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+
406411
int access_or_warn(const char *path, int mode)
407412
{
408413
int ret = access(path, mode);
409414
if (ret && errno != ENOENT)
410-
warning(_("unable to access '%s': %s"), path, strerror(errno));
415+
warn_on_inaccessible(path);
411416
return ret;
412417
}
413418

0 commit comments

Comments
 (0)