Skip to content

Commit 5437f0f

Browse files
committed
fixup! mingw: add a cache below mingw's lstat and dirent implementations
Since df3458e (refs API: make parse_loose_ref_contents() not set errno, 2021-10-16), `files_read_raw_ref()` assumes that `errno` is always set to a non-zero value upon failure. It even goes so far as to hard-code that assumption in a `BUG()` when that assumption is not met, rather than fail gracefully. According to https://pubs.opengroup.org/onlinepubs/9699919799/functions/lstat.html, `lstat()` shall indeed set `errno` upon failure, and https://pubs.opengroup.org/onlinepubs/9699919799/functions/errno.html indicates that indeed, the code may rely on `errno` being set to a non-zero value upon failure. In `fscache_lstat()`, we did not set `errno` upon a cache miss (which indicates that the item did not exist at the time the `lstat()` values were cached), and therefore we now trigger this problem all the time. Let's set `errno=ENOENT` when no entry was found. This fixes #3674 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 8084c8c commit 5437f0f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

compat/win32/fscache.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,10 @@ int fscache_lstat(const char *filename, struct stat *st)
598598
fsentry_init(&key[0].u.ent, NULL, filename, dirlen);
599599
fsentry_init(&key[1].u.ent, &key[0].u.ent, filename + base, len - base);
600600
fse = fscache_get(cache, &key[1].u.ent);
601-
if (!fse)
601+
if (!fse) {
602+
errno = ENOENT;
602603
return -1;
604+
}
603605

604606
/*
605607
* Special case symbolic links: FindFirstFile()/FindNextFile() did not

0 commit comments

Comments
 (0)