(dir: &Path)
| 930 | } |
| 931 | |
| 932 | fn 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 | } |
no test coverage detected