Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

A WSL distribution's size leaves out /proc, /sys, /dev and the Windows drives (899)

denfry95cefcea3f07
diff --git a/crates/rf-win/src/foldersize.rs b/crates/rf-win/src/foldersize.rs
index 5ec752ab..ac2f592f 100644
--- a/crates/rf-win/src/foldersize.rs
+++ b/crates/rf-win/src/foldersize.rs
@@ -228,6 +228,22 @@ fn finish(s: &Sched, job: &Job) {
s.jobs.lock().retain(|j| !(Arc::ptr_eq(&j.batch, &job.batch) && j.i == job.i));
}
+/// A folder of a WSL distribution that holds no files of its own disk: the kernel's views (`/proc`, `/sys`, `/dev`) and the
+/// Windows drives mounted under `/mnt`. `/proc/kcore` alone says it is 128 TB, so a distribution's root measured as 128 TB
+/// (issue 899), and `/mnt/c` would count all of C: a second time. Not followed, as `du -x` does not leave the distribution's disk.
+fn wsl_not_on_disk(dir: &Path) -> bool {
+ let s = dir.to_string_lossy();
+ // (the host's name in either case; the folders inside are Linux's, where case counts)
+ let host = |p: &str| s.get(..p.len()).filter(|h| h.eq_ignore_ascii_case(p)).map(|_| &s[p.len()..]);
+ let Some(rest) = host(r"\\wsl.localhost\").or_else(|| host(r"\\wsl$\")) else { return false };
+ let parts: Vec<&str> = rest.split('\\').filter(|p| !p.is_empty()).collect();
+ match parts.as_slice() {
+ [_, top] => matches!(*top, "proc" | "sys" | "dev"),
+ [_, "mnt", drive] => drive.len() == 1 && drive.as_bytes()[0].is_ascii_alphabetic(),
+ _ => false,
+ }
+}
+
fn process(s: &Sched, job: &Job, dir: PathBuf) {
let slot = &job.batch.slots[job.i];
if job.batch.stop.load(Ordering::Relaxed) {
@@ -269,7 +285,10 @@ fn process(s: &Sched, job: &Job, dir: PathBuf) {
return;
}
if a & attrs::DIRECTORY != 0 {
- subdirs.push(dir.join(from_wide(n)));
+ let sub = dir.join(from_wide(n));
+ if !wsl_not_on_disk(&sub) {
+ subdirs.push(sub);
+ }
} else {
let size = ((d.nFileSizeHigh as u64) << 32) | d.nFileSizeLow as u64;
bytes += size;
@@ -725,6 +744,25 @@ mod tests {
std::fs::remove_dir_all(&root).unwrap();
}
+ #[test]
+ fn a_wsl_distributions_kernel_views_and_windows_drives_are_not_measured() {
+ let no = |p: &str| super::wsl_not_on_disk(Path::new(p));
+ for p in [r"\\wsl.localhost\docker-desktop\proc", r"\\wsl$\Ubuntu\sys", r"\\WSL.LOCALHOST\Ubuntu\dev", r"\\wsl.localhost\Ubuntu\mnt\c"] {
+ assert!(no(p), "{p}");
+ }
+ for p in [
+ r"\\wsl.localhost\Ubuntu\home",
+ r"\\wsl.localhost\Ubuntu\home\proc",
+ r"\\wsl.localhost\Ubuntu\mnt\backup",
+ r"\\wsl.localhost\Ubuntu\Proc",
+ r"\\wsl.localhost\proc",
+ r"C:\proc",
+ r"\\server\share\proc",
+ ] {
+ assert!(!no(p), "{p}");
+ }
+ }
+
#[test]
fn skips_reparse_points() {
let root = tree("junc");