diff options
author | sharkdp <davidpeter@web.de> | 2019-09-21 11:42:51 +0200 |
---|---|---|
committer | sharkdp <davidpeter@web.de> | 2019-09-21 11:42:51 +0200 |
commit | 69f8027c4a43ed7c21aafa91c0f2f53ddf136706 (patch) | |
tree | c16399724b9adf3ba65afd7a88cda305df46cd56 | |
parent | a09b52204faeabe564e8890942f5b934db4e62a2 (diff) |
Move UniqueId functions to unique_id module
-rw-r--r-- | src/walk/mod.rs | 12 | ||||
-rw-r--r-- | src/walk/unique_id.rs | 31 | ||||
-rw-r--r-- | src/walk/unix.rs | 17 | ||||
-rw-r--r-- | src/walk/windows.rs | 9 |
4 files changed, 30 insertions, 39 deletions
diff --git a/src/walk/mod.rs b/src/walk/mod.rs index 889eceb..d826096 100644 --- a/src/walk/mod.rs +++ b/src/walk/mod.rs @@ -9,17 +9,7 @@ use rayon::{self, prelude::*}; mod unique_id; -#[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::*; - -use unique_id::UniqueID; +use unique_id::{generate_unique_id, UniqueID}; pub enum Err { NoMetadataForPath(PathBuf), diff --git a/src/walk/unique_id.rs b/src/walk/unique_id.rs index 59d3cc2..eb44e72 100644 --- a/src/walk/unique_id.rs +++ b/src/walk/unique_id.rs @@ -1,5 +1,32 @@ #[derive(Eq, PartialEq, Hash)] pub struct UniqueID { - pub device: u64, - pub inode: u64, + device: u64, + inode: u64, +} + +#[cfg(not(windows))] +pub fn generate_unique_id(metadata: &std::fs::Metadata) -> Option<UniqueID> { + use std::os::unix::fs::MetadataExt; + // 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 { + device: metadata.dev(), + inode: metadata.ino(), + }) + } else { + None + } +} + +#[cfg(windows)] +pub fn generate_unique_id(_metadata: &std::fs::Metadata) -> Option<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 } diff --git a/src/walk/unix.rs b/src/walk/unix.rs deleted file mode 100644 index 6d918d7..0000000 --- a/src/walk/unix.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::os::unix::fs::MetadataExt; - -use crate::walk::unique_id::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 { - device: metadata.dev(), - inode: metadata.ino(), - }) - } else { - None - } -} diff --git a/src/walk/windows.rs b/src/walk/windows.rs deleted file mode 100644 index 43cdff2..0000000 --- a/src/walk/windows.rs +++ /dev/null @@ -1,9 +0,0 @@ -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 -} |