Skip to content

Commit

Permalink
Enable Windows builds
Browse files Browse the repository at this point in the history
Fixes sharkdp#32.
  • Loading branch information
fawick committed Sep 20, 2019
1 parent e8b8216 commit 262b98b
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 13 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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ name = "diskus"
readme = "README.md"
repository = "https://github.com/sharkdp/diskus"
version = "0.5.0"
edition = "2018"

[dependencies]
num_cpus = "1.0"
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,16 @@ 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.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ extern crate rayon;

pub mod walk;

pub use walk::Walk;
pub use crate::walk::Walk;
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::path::PathBuf;
use clap::{App, AppSettings, Arg};
use humansize::{file_size_opts, FileSize};

use walk::Walk;
use crate::walk::Walk;

fn print_result(size: u64) {
println!(
Expand Down
21 changes: 10 additions & 11 deletions src/walk.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 @@ -9,8 +8,15 @@ use crossbeam_channel as channel;
use rayon;
use rayon::prelude::*;

#[derive(Eq, PartialEq, Hash)]
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 +27,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
18 changes: 18 additions & 0 deletions src/walk/unix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::path::PathBuf;
use std::os::unix::fs::MetadataExt;


#[derive(Eq, PartialEq, Hash)]
pub struct UniqueID(u64, u64);


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
}
}
6 changes: 6 additions & 0 deletions src/walk/windows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Eq, PartialEq, Hash)]
pub struct UniqueID(String);

pub fn generate_unique_id(_metadata: &std::fs::Metadata) -> Option<UniqueID> {
None
}

0 comments on commit 262b98b

Please sign in to comment.