Description
I've been trying to track this one down for a while with little success. So far I've been able to confirm that no external programs are holding long-standing locks on any of the files in the directory, and I've confirmed that it happens with trivial rust programs such as the following:
use std::fs;
fn main() {
println!("{:?}", fs::remove_dir_all("<path>"));
}
I've also confirmed that deleting the folder from explorer (equivalent to using SHFileOperation), or using rmdir
on the command line will always succeed.
Currently my best guess is that either windows or other programs are holding transient locks on some of the files in the directory, possibly as part of the directory indexing windows performs to enable efficient searching.
Several factors led me to think this:
fs::remove_dir_all
will pretty much always succeed on the second or third invocations.- it seems to happen most commonly when dealing with large numbers of text files
- unlocker and other tools show no active handles to any files in the directory
Maybe there should be some sort of automated retry system, such that temporary locks do not hinder progress?
edit:
The errors returned seem somewhat random: sometimes it gives a "directory is not empty" error, while sometimes it will show up as an "access denied" error.