Skip to content

Commit

Permalink
Enable Windows builds
Browse files Browse the repository at this point in the history
Fixes #32.
  • Loading branch information
fawick authored and sharkdp committed Sep 20, 2019
1 parent e8b8216 commit f048cf8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
22 changes: 12 additions & 10 deletions src/walk.rs → src/walk/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashSet;
use std::fs;
use std::os::unix::fs::MetadataExt;
use std::path::PathBuf;
use std::thread;

Expand All @@ -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),
Expand All @@ -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();

Expand Down
14 changes: 14 additions & 0 deletions src/walk/unix.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
13 changes: 13 additions & 0 deletions src/walk/windows.rs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit f048cf8

Please sign in to comment.