Commit 230be16
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: 3467906101 parent bf32cb8 commit 230be16
1 file changed
Lines changed: 28 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
907 | 907 | | |
908 | 908 | | |
909 | 909 | | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
910 | 917 | | |
911 | 918 | | |
912 | 919 | | |
| |||
927 | 934 | | |
928 | 935 | | |
929 | 936 | | |
930 | | - | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
931 | 945 | | |
932 | 946 | | |
933 | 947 | | |
934 | 948 | | |
935 | | - | |
936 | | - | |
937 | | - | |
938 | | - | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
939 | 962 | | |
940 | 963 | | |
941 | 964 | | |
| |||
0 commit comments