From: Junio C Hamano Date: Tue, 13 Jun 2017 20:47:09 +0000 (-0700) Subject: Merge branch 'nd/fopen-errors' X-Git-Tag: v2.14.0-rc0~95 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/b9a7d55d938a81eb6268196b789d573437492100?hp=--cc Merge branch 'nd/fopen-errors' We often try to open a file for reading whose existence is optional, and silently ignore errors from open/fopen; report such errors if they are not due to missing files. * nd/fopen-errors: mingw_fopen: report ENOENT for invalid file names mingw: verify that paths are not mistaken for remote nicknames log: fix memory leak in open_next_file() rerere.c: move error_errno() closer to the source system call print errno when reporting a system call error wrapper.c: make warn_on_inaccessible() static wrapper.c: add and use fopen_or_warn() wrapper.c: add and use warn_on_fopen_errors() config.mak.uname: set FREAD_READS_DIRECTORIES for Darwin, too config.mak.uname: set FREAD_READS_DIRECTORIES for Linux and FreeBSD clone: use xfopen() instead of fopen() use xfopen() in more places git_fopen: fix a sparse 'not declared' warning --- b9a7d55d938a81eb6268196b789d573437492100 diff --cc dir.c index 70f2de38f2,be616e884e..1759063817 --- a/dir.c +++ b/dir.c @@@ -752,12 -745,12 +752,12 @@@ static int add_excludes(const char *fna fd = open(fname, O_RDONLY); if (fd < 0 || fstat(fd, &st) < 0) { - if (errno != ENOENT) - warn_on_inaccessible(fname); - if (0 <= fd) + if (fd < 0) + warn_on_fopen_errors(fname); + else close(fd); - if (!check_index || - (buf = read_skip_worktree_file_from_index(fname, &size, sha1_stat)) == NULL) + if (!istate || + (buf = read_skip_worktree_file_from_index(istate, fname, &size, sha1_stat)) == NULL) return -1; if (size == 0) { free(buf); diff --cc wrapper.c index 708e98a965,b117eb14a4..4632c7d4c0 --- a/wrapper.c +++ b/wrapper.c @@@ -576,15 -602,10 +602,10 @@@ int remove_or_warn(unsigned int mode, c return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file); } - void warn_on_inaccessible(const char *path) - { - warning_errno(_("unable to access '%s'"), path); - } - static int access_error_is_ok(int err, unsigned flag) { - return err == ENOENT || err == ENOTDIR || - ((flag & ACCESS_EACCES_OK) && err == EACCES); + return (is_missing_file_error(err) || + ((flag & ACCESS_EACCES_OK) && err == EACCES)); } int access_or_warn(const char *path, int mode, unsigned flag)