Skip to content

Commit 35e6e21

Browse files
matheustavaresgitster
authored andcommitted
entry: check for fstat() errors after checkout
In 11179eb ("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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af6b65d commit 35e6e21

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

entry.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ static int fstat_output(int fd, const struct checkout *state, struct stat *st)
113113
/* use fstat() only when path == ce->name */
114114
if (fstat_is_reliable() &&
115115
state->refresh_cache && !state->base_dir_len) {
116-
fstat(fd, st);
117-
return 1;
116+
return !fstat(fd, st);
118117
}
119118
return 0;
120119
}

0 commit comments

Comments
 (0)