Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Windows builds #36

Merged
merged 5 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ 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
rust: 1.34.0
env: TARGET=x86_64-unknown-linux-gnu


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.

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,18 @@ Check out the [release page](https://github.com/sharkdp/diskus/releases) for bin

### Via cargo

If you have Rust 1.29 or higher, you can install `diskus` from source via `cargo`:
If you have Rust 1.34 or higher, you can install `diskus` from source via `cargo`:
```
cargo install diskus
```

## Windows caveats

Windows-internal tools such as Powershell, Explorer or `dir` are not respecting hardlinks or
junction points when determining the size of a directory. `diskus` does the same and counts
such entries multiple times (on Unix systems, multiple hardlinks to a single file are counted
just once).

## License

Licensed under either of
Expand Down
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
}
}
9 changes: 9 additions & 0 deletions src/walk/windows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub fn generate_unique_id(_metadata: &std::fs::Metadata) -> Option<super::UniqueID> {
// Windows-internal tools such as Powershell, Explorer or `dir` are not respecting hardlinks
// or junction points when determining the size of a directory. `diskus` does the same and
// counts such entries multiple times (on Unix systems, multiple hardlinks to a single file are
// counted just once).
//
// See: https://github.com/sharkdp/diskus/issues/32
None
}