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 | |
parent | e8b8216801abc924f5d6cbceaf48c0faa55e959a (diff) |
Enable Windows builds
Fixes #32.
-rw-r--r-- | .travis.yml | 3 | ||||
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | README.md | 14 | ||||
-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 |
6 files changed, 58 insertions, 10 deletions
diff --git a/.travis.yml b/.travis.yml index 0e08879..146ec3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,9 @@ matrix: - os: osx rust: stable env: TARGET=x86_64-apple-darwin + - os: windows + rust: stable + env: TARGET=x86_64-pc-windows-msvc # Minimum Rust supported channel. - os: linux rust: 1.29.0 @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "ansi_term" version = "0.11.0" @@ -125,3 +125,17 @@ Licensed under either of * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. + + +## Windows caveats + + 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, it has been decided that diskus will count + any such entries multiple times. too. See + https://github.com/sharkdp/diskus/issues/32#issuecomment-532817905 for + an example of this behaviour. 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 +} |