Expose is_same_file function.

A case could be made for splitting this out into a separate crate,
but I'm fine with keeping it part of walkdir for now.
This commit is contained in:
Andrew Gallant 2016-10-29 12:27:41 -04:00
parent 47271fba42
commit 737af4f2d5
2 changed files with 26 additions and 3 deletions

View File

@ -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;

View File

@ -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<P, Q>(
path1: P,
path2: Q,
) -> io::Result<bool> where P: AsRef<Path>, Q: AsRef<Path> {
impl_is_same_file(path1, path2)
}
#[cfg(unix)]
fn impl_is_same_file<P, Q>(
p1: P,
p2: Q,
) -> io::Result<bool>
@ -31,7 +54,7 @@ where P: AsRef<Path>, Q: AsRef<Path> {
}
#[cfg(windows)]
pub fn is_same_file<P, Q>(
fn impl_is_same_file<P, Q>(
p1: P,
p2: Q,
) -> io::Result<bool>