Skip to main content

dir_size_with_hardlinks

Function dir_size_with_hardlinks 

Source
pub fn dir_size_with_hardlinks(path: &Path) -> DirSizeBreakdown
Expand description

dir_size, but hardlink-aware.

pnpm and bun do not copy packages into node_modules; they hardlink them from a machine-wide store, so summing file sizes counts bytes the store keeps after the delete and promises space a prune cannot deliver. Here a physical file is counted once no matter how many names it has inside the tree, and counts as freed only when every one of its links is inside the tree. A store that fell back to copying — a different volume, a filesystem without hardlinks — leaves the link count at one, so copied installs still count in full. A file whose link count cannot be read is counted as freed, which errs toward the plain dir_size figure.