# child_process: Fix regression on Windows for FAT filesystems · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/3f7166eb8bd714b412889d8ded71fd839111c624)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 3f7166eb8bd714b412889d8ded71fd839111c624

Requested commit: 3f7166eb8bd714b412889d8ded71fd839111c624

Commit: 3f7166eb8bd714b412889d8ded71fd839111c624

Tree: e3e2e41c75e70ecbce184888b43795c81d9d0ac0

Author: Ryan Liptak

Committer: Andrew Kelley

## Message

```
child_process: Fix regression on Windows for FAT filesystems

This fixes a regression caused by https://github.com/ziglang/zig/pull/13993

As an optimization, the first call to `NtQueryDirectoryFile` would only ask for a single result and assume that if the result returned did not match the app_name exactly, then the unappended app_name did not exist. However, this relied on the assumption that the unappended app_name would always be returned first, but that only seems to be the case on NTFS. On FAT filesystems, the order of returned files can be different, which meant that it could assume the unappended file doesn't exist when it actually does.

This commit fixes that by fully iterating the wildcard matches via `NtQueryDirectoryFile` and taking note of any unappended/PATHEXT-appended filenames it finds. In practice, this strategy does not introduce a speed regression compared to the previous (buggy) implementation.

Benchmark 1 (10 runs): winpathbench-master.exe
  measurement          mean ± σ            min … max           outliers         delta
  wall_time           508ms ± 4.08ms     502ms …  517ms          1 (10%)        0%
  peak_rss           3.62MB ± 2.76KB    3.62MB … 3.63MB          0 ( 0%)        0%
Benchmark 2 (10 runs): winpathbench-fat32-fix.exe
  measurement          mean ± σ            min … max           outliers         delta
  wall_time           500ms ± 21.4ms     480ms …  535ms          0 ( 0%)          -  1.5% ±  2.8%
  peak_rss           3.62MB ± 2.76KB    3.62MB … 3.63MB          0 ( 0%)          -  0.0% ±  0.1%

---

Partially addresses #16374 (it fixes `zig build` on FAT32 when no `zig-cache` is present)

```

## Parents

- [7dcbabef512403382f4647e2c7cc0c900ecae913](https://git.cafe/gitcafe/zig/commit/7dcbabef512403382f4647e2c7cc0c900ecae913?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/3f7166eb8bd714b412889d8ded71fd839111c624?format=markdown)
