this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(progress): follow symlinks in container pre-walk to match walker

+23 -4
+23 -4
src/backends/containers.rs
··· 7 7 use std::path::Path; 8 8 9 9 /// Sum sizes of all regular files reachable from the given paths, recursing 10 - /// into directories. Best-effort: anything we can't stat (permission denied, 11 - /// racy deletion) is counted as zero; the bar may finish short rather than 12 - /// fail the run. 10 + /// into directories. Uses `fs::metadata` (follows symlinks) so that the 11 + /// file-vs-directory judgment matches `Path::is_file` / `Path::is_dir` 12 + /// semantics used by each backend's walker — otherwise a symlink to a file 13 + /// would contribute 0 to the total while the walker reads (and bar-ticks) 14 + /// the full target. Best-effort: anything we can't stat (permission denied, 15 + /// racy deletion, broken symlink) is counted as zero; the bar may finish 16 + /// short rather than fail the run. 13 17 pub fn total_input_bytes<P: AsRef<Path>>(paths: &[P]) -> u64 { 14 18 paths.iter().map(|p| sum_path(p.as_ref())).sum() 15 19 } 16 20 17 21 fn sum_path(path: &Path) -> u64 { 18 - let Ok(meta) = std::fs::symlink_metadata(path) else { 22 + let Ok(meta) = std::fs::metadata(path) else { 19 23 return 0; 20 24 }; 21 25 if meta.is_file() { ··· 57 61 total_input_bytes(&[std::path::PathBuf::from("/nope/xx")]), 58 62 0 59 63 ); 64 + } 65 + 66 + /// Symlinks to regular files must contribute their target's size so the 67 + /// bar total matches what the walkers actually read. Regression for 68 + /// tar/zip/7z bars overshooting past 100% on directories containing 69 + /// symlinks. 70 + #[cfg(unix)] 71 + #[test] 72 + fn follows_symlink_to_file() { 73 + let dir = assert_fs::TempDir::new().unwrap(); 74 + dir.child("target.txt").write_str("abcdefghij").unwrap(); 75 + std::os::unix::fs::symlink(dir.path().join("target.txt"), dir.path().join("link.txt")) 76 + .unwrap(); 77 + // target.txt (10) + link.txt following to target (10) = 20 78 + assert_eq!(total_input_bytes(&[dir.path().to_path_buf()]), 20); 60 79 } 61 80 }