From: Derrick Stolee <stolee@gmail.com>
To: Matheus Tavares <matheus.bernardino@usp.br>, git@vger.kernel.org
Subject: Re: [PATCH] entry: check for fstat() errors after checkout
Date: Thu, 9 Jul 2020 07:41:30 -0400 [thread overview]
Message-ID: <882592a4-ffb7-924c-b52a-3287b11318b8@gmail.com> (raw)
In-Reply-To: <fbde5e1c9042ea06b448bc759cea9d45e300961f.1594260597.git.matheus.bernardino@usp.br>
On 7/8/2020 10:10 PM, Matheus Tavares wrote:
> In 11179eb311 ("entry.c: check if file exists after checkout",
> 2017-10-05) we started checking the result of the lstat() call done
> after writing a file, to avoid writing garbage to the corresponding
> cache entry. However, the code skips calling lstat() if it's possible
> to use fstat() when it still has the file descriptor open. And when
> calling fstat() we don't do the same error checking. To fix that, let
> the callers of fstat_output() know when fstat() fails. In this case,
> write_entry() will try to use lstat() and properly report an error if
> that fails as well.
Looking at this for the first time, I was confused because 11179eb311
doesn't touch these lines. But that's the point: it should have.
Thanks for finding this! I wonder if there is a way to expose this
behavior in a test... it definitely seems like this is only something
that happens if there is a failure in the filesystem, so I'm not sure
such a thing is possible.
It would just be nice to know the ramifications of this change in
behavior, keeping in mind that this behavior started way back in
e4c7292353 (write_entry(): use fstat() instead of lstat() when file is
open, 2009-02-09), over 11 years ago!
Thanks,
-Stolee
> Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
> ---
> entry.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/entry.c b/entry.c
> index 00b4903366..449bd32dee 100644
> --- a/entry.c
> +++ b/entry.c
> @@ -113,8 +113,7 @@ static int fstat_output(int fd, const struct checkout *state, struct stat *st)
> /* use fstat() only when path == ce->name */
> if (fstat_is_reliable() &&
> state->refresh_cache && !state->base_dir_len) {
> - fstat(fd, st);
> - return 1;
> + return !fstat(fd, st);
> }
> return 0;
> }
>
next prev parent reply other threads:[~2020-07-09 11:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-09 2:10 [PATCH] entry: check for fstat() errors after checkout Matheus Tavares
2020-07-09 11:41 ` Derrick Stolee [this message]
2020-07-09 14:08 ` Junio C Hamano
2020-07-09 17:08 ` Junio C Hamano
2020-07-09 17:39 ` Matheus Tavares Bernardino
2020-07-09 18:09 ` Junio C Hamano
2020-07-21 15:39 ` Matheus Tavares Bernardino
2020-07-21 20:00 ` Junio C Hamano
2020-07-21 20:57 ` Derrick Stolee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=882592a4-ffb7-924c-b52a-3287b11318b8@gmail.com \
--to=stolee@gmail.com \
--cc=git@vger.kernel.org \
--cc=matheus.bernardino@usp.br \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).