Re: [PATCH] dir.c: print correct errno when opendir() fails
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 19, 2018, 21:09 UTC
- Message-ID
- <xmqqa7x9pnda.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20180118095036.29422-1-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
Show 9 quoted lines
> The call invalidate_directory() between opendir() and warning_errno() in > theory could make some system calls and change errno. Prevent that by > warning immediately after opendir(). > > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> > --- > This is on top of nd/fix-untracked-cache-invalidation which is now on > 'next'. Sorry I waited too long to send the replacement and it's now > too late.
Well, we'll see a rewind of 'next' soonish anyway, so you can just tell me to tentatively kick it back to 'pu' to be replaced with a reroll if you prefer.
Show 24 quoted lines
> dir.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/dir.c b/dir.c
> index dd1e50c328..55736d3e2a 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -1795,14 +1795,14 @@ static int open_cached_dir(struct cached_dir *cdir,
> return 0;
> c_path = path->len ? path->buf : ".";
> cdir->fdir = opendir(c_path);
> + if (!cdir->fdir)
> + warning_errno(_("could not open directory '%s'"), c_path);
> if (dir->untracked) {
> invalidate_directory(dir->untracked, untracked);
> dir->untracked->dir_opened++;
> }
> - if (!cdir->fdir) {
> - warning_errno(_("could not open directory '%s'"), c_path);
> + if (!cdir->fdir)
> return -1;
> - }
> return 0;
> }