Skip to content

Commit

Permalink
fixup! mingw: add a cache below mingw's lstat and dirent implementations
Browse files Browse the repository at this point in the history
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 <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Feb 1, 2022
1 parent 8084c8c commit 5437f0f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compat/win32/fscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,10 @@ int fscache_lstat(const char *filename, struct stat *st)
fsentry_init(&key[0].u.ent, NULL, filename, dirlen);
fsentry_init(&key[1].u.ent, &key[0].u.ent, filename + base, len - base);
fse = fscache_get(cache, &key[1].u.ent);
if (!fse)
if (!fse) {
errno = ENOENT;
return -1;
}

/*
* Special case symbolic links: FindFirstFile()/FindNextFile() did not
Expand Down

0 comments on commit 5437f0f

Please sign in to comment.