# fs.Dir.deleteTree: Reduce the number of failing deleteFile calls · gitcafe/zig

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

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

Visibility: public

Requested revision: 8cec8f6dddeec46f609afd42c6024c55e5c126d9

Requested commit: 8cec8f6dddeec46f609afd42c6024c55e5c126d9

Commit: 8cec8f6dddeec46f609afd42c6024c55e5c126d9

Tree: 07af7bbc28128723ee47f5baa97b81086828bc50

Author: Ryan Liptak

Committer: Ryan Liptak

## Message

```
fs.Dir.deleteTree: Reduce the number of failing deleteFile calls

There are two parts to this:

1. The deleteFile call on the sub_path has been moved outside the loop, since if the first call fails with `IsDir` then it's very likely that all the subsequent calls will do the same. Instead, if the `openIterableDir` call ever hits `NotDir` after the `deleteFile` hit `IsDir`, then we assume that the tree was deleted at some point and can consider the deleteTree a success.

2. Inside the `dir_it.next()` loop, we look at entry.kind and only try doing the relevant (deleteFile/openIterableDir) operation, but always fall back to the other if we get the relevant error (NotDir/IsDir).

```

## Parents

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

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