Skip to main content

clear_directory

Function clear_directory 

Source
pub fn clear_directory(dir: &Path) -> Result<(), Box<dyn Error + Send + Sync>>
Expand description

Remove and recreate a directory.

A symlink at dir is unlinked, never followed: exists() resolves through links, so a dangling link would otherwise survive the wipe and create_dir_all would then create the link’s target directory — outside the tree the caller means to confine extraction to.

Retries on ENOTEMPTY — observed under CI overlay/tmpfs filesystems where the final rmdir races with leftover dentries even after all children are gone. Linux returns 39, macOS/BSD return 66 — match both.