# std.fs: End iteration on Linux/WASI during Iterator.next when hitting \`ENOENT\` · gitcafe/zig

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

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

Visibility: public

Requested revision: 75e5b38410e81ddf21ba37a874ee2bb13dea7477

Requested commit: 75e5b38410e81ddf21ba37a874ee2bb13dea7477

Commit: 75e5b38410e81ddf21ba37a874ee2bb13dea7477

Tree: 86bc98c9bf81d13ca30e676e533d58c956196b72

Author: Ryan Liptak

Committer: GitHub

## Message

```
std.fs: End iteration on Linux/WASI during Iterator.next when hitting `ENOENT`

`getdents` on Linux can return `ENOENT` if the directory referred to by the fd is deleted during iteration. Returning null when this happens makes sense because:

- `ENOENT` is specific to the Linux implementation of `getdents`
- On other platforms like FreeBSD, `getdents` returns `0` in this scenario, which is functionally equivalent to the `.NOENT => return null` handling on Linux
- In all the usage sites of `Iterator.next` throughout the standard library, translating `ENOENT` returned from `next` as null was the best way to handle it, so the use-case for handling the exact `ENOENT` scenario specifically may not exist to a relevant extent

Previously, ENOENT being returned would trigger `os.unexpectedErrno`.

Closes #12211
```

## Parents

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

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