git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] entry: check for fstat() errors after checkout
@ 2020-07-09  2:10 Matheus Tavares
  2020-07-09 11:41 ` Derrick Stolee
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Matheus Tavares @ 2020-07-09  2:10 UTC (permalink / raw)
  To: git

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.

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;
 }
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-07-21 20:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-09  2:10 [PATCH] entry: check for fstat() errors after checkout Matheus Tavares
2020-07-09 11:41 ` Derrick Stolee
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

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).