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

Function dir_size

src/migrate/inventory.rs:932–963  ·  view source on GitHub ↗
(dir: &Path)

Source from the content-addressed store, hash-verified

930}
931
932fn dir_size(dir: &Path) -> u64 {
933 fn walk(path: &Path, total: &mut u64, visited_dirs: &mut HashSet<PathBuf>) {
934 let Ok(meta) = std::fs::symlink_metadata(path) else {
935 return;
936 };
937 if meta.file_type().is_symlink() {
938 *total = total.saturating_add(meta.len());
939 return;
940 }
941 if !meta.is_dir() {
942 if meta.is_file() {
943 *total = total.saturating_add(meta.len());
944 }
945 return;
946 }
947 let key = path.canonicalize().unwrap_or_else(|_| path.to_path_buf());
948 if !visited_dirs.insert(key) {
949 return;
950 }
951 let Ok(entries) = std::fs::read_dir(path) else {
952 return;
953 };
954 for entry in entries.flatten() {
955 walk(&entry.path(), total, visited_dirs);
956 }
957 }
958
959 let mut total = 0;
960 let mut visited_dirs = HashSet::new();
961 walk(dir, &mut total, &mut visited_dirs);
962 total
963}

Callers 2

inspect_project_storeFunction · 0.85
record_optional_artifactFunction · 0.85

Calls 1

walkFunction · 0.70

Tested by

no test coverage detected