Skip to main content

prune_dir

Function prune_dir 

Source
pub fn prune_dir(dir: &Path, limit: u64) -> Result<Prune>
Expand description

Delete files under dir oldest-first until its size is at or below limit.

The comparison is over_limit, so a directory exactly at the cap is left alone. Oldest-first keeps the newest generation of artifacts — the one the next run reuses — and sheds the generations that only compile history. A deleted file costs the next build a rebuild of that one unit; deleting the whole directory would cost it everything, which is precisely the work prune_dir is keeping for it.

Empty directories left behind are swept depth-first, so cargo’s deep fingerprint/deps trees do not outlive the files that made them.

Nothing is deleted when the directory is missing.