Skip to content

Commit

Permalink
Don't pay extra on linux for helping with #53
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 22, 2020
1 parent 22a13fb commit d18191d
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ use crate::{crossdev, get_size_or_panic, InodeFilter, WalkOptions};
use anyhow::Result;
use filesize::PathExt;
use petgraph::{graph::NodeIndex, stable_graph::StableGraph, Directed, Direction};
use std::{path::PathBuf, time::Duration, time::Instant};
use std::{
fs::Metadata,
io,
path::{Path, PathBuf},
time::{Duration, Instant},
};

pub type TreeIndex = NodeIndex;
pub type Tree = StableGraph<EntryData, (), Directed>;
Expand Down Expand Up @@ -78,6 +83,16 @@ impl Traversal {
// Also means that we will spin up a bunch of threads per root path, instead of reusing them.
walk_options.threads = num_cpus::get();
}

#[cfg(not(windows))]
fn size_on_disk(_parent: &Path, name: &Path, meta: &Metadata) -> io::Result<u64> {
name.size_on_disk_fast(meta)
}
#[cfg(windows)]
fn size_on_disk(parent: &Path, name: &Path, meta: &Metadata) -> io::Result<u64> {
parent.join(name).size_on_disk_fast(meta)
}

for path in input.into_iter() {
let mut last_seen_eid = 0;
let device_id = crossdev::init(path.as_ref())?;
Expand Down Expand Up @@ -105,15 +120,13 @@ impl Traversal {
if walk_options.apparent_size {
m.len()
} else {
entry
.parent_path
.join(&data.name)
.size_on_disk_fast(m)
.unwrap_or_else(|_| {
size_on_disk(&entry.parent_path, &data.name, m).unwrap_or_else(
|_| {
t.io_errors += 1;
data.metadata_io_error = true;
0
})
},
)
}
}
Some(Ok(_)) => 0,
Expand Down

0 comments on commit d18191d

Please sign in to comment.