summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Matheus Tavares <matheus.bernardino@usp.br>2020-07-08 23:10:39 -0300
committerLibravatar Junio C Hamano <gitster@pobox.com>2020-07-09 09:45:06 -0700
commit35e6e212fdea3a22abe0dc5867b974b30b787be0 (patch)
tree0d5f2e0dc4fd31bae42f9d923eb17bc58b6f8b07
parentGit 2.26.2 (diff)
downloadtgif-35e6e212fdea3a22abe0dc5867b974b30b787be0.tar.xz
entry: check for fstat() errors after checkout
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--entry.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/entry.c b/entry.c
index 53380bb614..2afac33699 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;
}