Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not interleave readdir() calls with deletion of directory entries.
On macOS and some other non-Linux OSes, on some filesystems, readdir(dir) may return NULL (with zero errno) after an entry in dir has been deleted. We thus need to readdir() all directory entries before starting to delete them. A benchmark (deleting 10 copies of the Linux kernel source) seems to show that the new approach is approximately as fast as the previous one (slightly faster on Linux, slightly slower on Mac), and in any case, is noticeably faster than the system's /bin/rm. Bazel's previous unix_jni DeleteTreesBelow implementation: 6.987 s (Linux/ext4); 89.44 s (Mac/APFS) New Bazel unix_jni DeleteTreesBelow implementation: 6.971 s (Linux/ext4); 90.46 s (Mac/APFS) `rm -rf`: 7.323 s (Linux/ext4); 99.09 s (Mac/APFS) RELNOTES: None. PiperOrigin-RevId: 346790610
- Loading branch information