Windows: Directory removal sometimes fails
On Windows, removing a directory recursively with
cmake -E remove_directory or
file(REMOVE_RECURSE) occasionally fails for a few reasons:
- Races with anti-virus tools locking recently created files.
- Races with other tools creating new entries in a directory.
- Races between removing all entries in a directory and removing the directory itself. NTFS deletion is not synchronous.
Our implementation currently uses KWSys
SystemTools::RemoveADirectory. It could be improved with a more robust removal approach.
Meanwhile some code paths are using
cmSystemTools::RepeatedRemoveDirectory to work around this.