diff --git a/src/lib.rs b/src/lib.rs index 6e8761a..958dad4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,7 +100,7 @@ use std::path::{Path, PathBuf}; use std::result; use std::vec; -use same_file::is_same_file; +pub use same_file::is_same_file; mod same_file; #[cfg(test)] mod tests; diff --git a/src/same_file.rs b/src/same_file.rs index 8ad15cf..b369bbf 100644 --- a/src/same_file.rs +++ b/src/same_file.rs @@ -16,8 +16,31 @@ use std::path::Path; // // ---AG -#[cfg(unix)] +/// Returns true if the two file paths may correspond to the same file. +/// +/// If there was a problem accessing either file path, then an error is +/// returned. +/// +/// Note that it's possible for this to produce a false positive on some +/// platforms. Namely, this can return true even if the two file paths *don't* +/// resolve to the same file. +/// +/// # Example +/// +/// ```rust,no_run +/// use walkdir::is_same_file; +/// +/// assert!(is_same_file("./foo", "././foo").unwrap_or(false)); +/// ``` pub fn is_same_file( + path1: P, + path2: Q, +) -> io::Result where P: AsRef, Q: AsRef { + impl_is_same_file(path1, path2) +} + +#[cfg(unix)] +fn impl_is_same_file( p1: P, p2: Q, ) -> io::Result @@ -31,7 +54,7 @@ where P: AsRef, Q: AsRef { } #[cfg(windows)] -pub fn is_same_file( +fn impl_is_same_file( p1: P, p2: Q, ) -> io::Result