diff options
author | Fabian Wickborn <fabian@wickborn.net> | 2019-09-18 19:48:12 +0200 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2019-09-20 22:11:24 +0200 |
commit | f048cf8978f21279a0db97fccffd9bca467e07fe (patch) | |
tree | 4b41c85c434cf8d92e9d28f0c67923f62e63b96b /src | |
parent | e8b8216801abc924f5d6cbceaf48c0faa55e959a (diff) |
Enable Windows builds
Fixes #32.
Diffstat (limited to 'src')
-rw-r--r-- | src/walk/mod.rs (renamed from src/walk.rs) | 22 | ||||
-rw-r--r-- | src/walk/unix.rs | 14 | ||||
-rw-r--r-- | src/walk/windows.rs | 13 |
3 files changed, 39 insertions, 10 deletions
diff --git a/src/walk.rs b/src/walk/mod.rs index 0125713..7fc3256 100644 --- a/src/walk.rs +++ b/src/walk/mod.rs @@ -1,6 +1,5 @@ use std::collections::HashSet; use std::fs; -use std::os::unix::fs::MetadataExt; use std::path::PathBuf; use std::thread; @@ -10,7 +9,17 @@ use rayon; use rayon::prelude::*; #[derive(Eq, PartialEq, Hash)] -struct UniqueID(u64, u64); +pub struct UniqueID(u64, u64); + +#[cfg(target_os = "windows")] +mod windows; +#[cfg(target_os = "windows")] +pub use self::windows::*; + +#[cfg(not(target_os = "windows"))] +mod unix; +#[cfg(not(target_os = "windows"))] +pub use self::unix::*; enum Message { SizeEntry(Option<UniqueID>, u64), @@ -21,14 +30,7 @@ enum Message { fn walk(tx: channel::Sender<Message>, entries: &[PathBuf]) { entries.into_par_iter().for_each_with(tx, |tx_ref, entry| { if let Ok(metadata) = entry.symlink_metadata() { - // If the entry has more than one hard link, generate - // a unique ID consisting of device and inode in order - // not to count this entry twice. - let unique_id = if metadata.is_file() && metadata.nlink() > 1 { - Some(UniqueID(metadata.dev(), metadata.ino())) - } else { - None - }; + let unique_id = generate_unique_id(&metadata); let size = metadata.len(); diff --git a/src/walk/unix.rs b/src/walk/unix.rs new file mode 100644 index 0000000..51d370a --- /dev/null +++ b/src/walk/unix.rs @@ -0,0 +1,14 @@ +use std::os::unix::fs::MetadataExt; + +use super::UniqueID; + +pub fn generate_unique_id(metadata: &std::fs::Metadata) -> Option<UniqueID> { + // If the entry has more than one hard link, generate + // a unique ID consisting of device and inode in order + // not to count this entry twice. + if metadata.is_file() && metadata.nlink() > 1 { + Some(UniqueID(metadata.dev(), metadata.ino())) + } else { + None + } +}
\ No newline at end of file diff --git a/src/walk/windows.rs b/src/walk/windows.rs new file mode 100644 index 0000000..8a3bcca --- /dev/null +++ b/src/walk/windows.rs @@ -0,0 +1,13 @@ +pub fn generate_unique_id(_metadata: &std::fs::Metadata) -> Option<super::UniqueID> { + // Since even the Windows-internal tools such as (but not limited to) + // - Powershell, + // - Explorer, + // - dir, + // are not respecting hardlinks or junction points when determining the + // size of a directory [1], it has been decided that diskus will count + // any such entries multiple times. too. + // + // Footnotes: + // [1] https://github.com/sharkdp/diskus/issues/32#issuecomment-532817905 + None +} |