MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / walk

Function walk

src/global.rs:315–333  ·  view source on GitHub ↗
(p: &Path, acc: &mut u64)

Source from the content-addressed store, hash-verified

313/// Returns the total size in bytes of every file under `dir`. Best-effort.
314pub(crate) fn tracedecay_dir_size(dir: &Path) -> u64 {
315 fn walk(p: &Path, acc: &mut u64) {
316 let Ok(entries) = std::fs::read_dir(p) else {
317 return;
318 };
319 for entry in entries.flatten() {
320 // One stat per entry instead of file_type() + metadata():
321 // `metadata()` already carries the file-type bits, so calling
322 // both means a redundant syscall on filesystems that don't
323 // cache the dirent stat.
324 let Ok(meta) = entry.metadata() else {
325 continue;
326 };
327 if meta.is_dir() {
328 walk(&entry.path(), acc);
329 } else if meta.is_file() {
330 *acc = acc.saturating_add(meta.len());
331 }
332 }
333 }
334 let mut total = 0u64;
335 walk(dir, &mut total);
336 total

Callers 1

tracedecay_dir_sizeFunction · 0.70

Calls 1

metadataMethod · 0.80

Tested by

no test coverage detected