entry: flush fscache after creating directories and writing files

When checkout.workers > 1 and core.fscache is enabled on Windows,
'git checkout <tree> -- <pathspec>' fails when restoring files into
directories that do not yet exist on disk. Two failure modes occur:

1. create_directories(): the fscache returns a stale directory listing
   that does not include a just-created directory. has_dirs_only_path()
   reports it as non-existent, triggering the unlink+mkdir recovery
   path which fails with 'cannot create directory: Directory not empty'.

2. write_pc_item(): after writing and closing a file, lstat() cannot
   see it through the stale fscache, failing with 'unable to stat
   just-written file'.

With workers=1, write_entry() calls flush_fscache() after each file,
keeping the cache in sync. With workers>1, enqueue_checkout() defers
the write (and the flush), leaving the cache stale for subsequent
entries.

Fix both by adding flush_fscache() calls after mkdir() in
create_directories() and before lstat() in write_pc_item(). On
non-Windows platforms flush_fscache() is a no-op.

Assisted-by: Claude Opus 4.6
Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
This commit is contained in:
Tyrie Vella
2026-05-18 09:50:39 -07:00
committed by Git for Windows Build Agent
parent 699534ae07
commit bd08683f99
3 changed files with 67 additions and 1 deletions

View File

@@ -395,6 +395,13 @@ void write_pc_item(struct parallel_checkout_item *pc_item,
goto out;
}
/*
* Flush the Windows fscache so that the lstat() below sees the
* file we just wrote. Without this, the cached parent directory
* listing may not yet include the new file entry.
*/
flush_fscache();
if (state->refresh_cache && !fstat_done && lstat(path.buf, &pc_item->st) < 0) {
error_errno("unable to stat just-written file '%s'", path.buf);
pc_item->status = PC_ITEM_FAILED;