Skip to content

Commit 11179eb

Browse files
larsxschneidergitster
authored andcommitted
entry.c: check if file exists after checkout
If we are checking out a file and somebody else racily deletes our file, then we would write garbage to the cache entry. Fix that by checking the result of the lstat() call on that file. Print an error to the user if the file does not exist. Reported-by: Jeff King <[email protected]> Signed-off-by: Lars Schneider <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 03b9533 commit 11179eb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

entry.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@ static int write_entry(struct cache_entry *ce,
341341
if (state->refresh_cache) {
342342
assert(state->istate);
343343
if (!fstat_done)
344-
lstat(ce->name, &st);
344+
if (lstat(ce->name, &st) < 0)
345+
return error_errno("unable to stat just-written file %s",
346+
ce->name);
345347
fill_stat_cache_info(ce, &st);
346348
ce->ce_flags |= CE_UPDATE_IN_BASE;
347349
state->istate->cache_changed |= CE_ENTRY_CHANGED;

0 commit comments

Comments
 (0)