# Package.Fetch: improved deletion algorithm · gitcafe/zig

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

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

Visibility: public

Requested revision: cd4397783f7ae86de867bed3346ea10547a94ee1

Requested commit: cd4397783f7ae86de867bed3346ea10547a94ee1

Commit: cd4397783f7ae86de867bed3346ea10547a94ee1

Tree: 4ce6a807c43bacfabee5312517ca6f35b118ad2d

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
Package.Fetch: improved deletion algorithm

Instead of every file deletion being followed by a recursive attempt to
remove the parent directory, while walking the directory, every
directory that will have nonzero files deleted from it is tracked in an
array hash map.

After all the threads have finished deleting and hashing, the parent
thread sorts the "suspicious" directories by length, descending,
ensuring that children appear before parents, and then iterates over the
array hash map, attempting a rmdir operation on each. Any rmdir that
succeeds appends the parent directory to the map so that it will be
removed if empty.

```

## Parents

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

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