Fix is_symlink()
method for Path
using added is_symlink()
method for Metadata
This commit is contained in:
parent
e1cf38fa89
commit
89c0f50b09
2 changed files with 26 additions and 3 deletions
|
@ -1007,6 +1007,30 @@ impl Metadata {
|
||||||
self.file_type().is_file()
|
self.file_type().is_file()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if this metadata is for a symbolic link file.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```no_run
|
||||||
|
/// use std::fs;
|
||||||
|
/// use std::path::Path;
|
||||||
|
/// use std::os::unix::fs::symlink;
|
||||||
|
///
|
||||||
|
/// fn main() -> std::io::Result<()> {
|
||||||
|
/// let link_path = Path::new("/link");
|
||||||
|
/// symlink("/origin_does_not_exists/", link_path)?;
|
||||||
|
///
|
||||||
|
/// let metadata = fs::symlink_metadata(link_path)?;
|
||||||
|
///
|
||||||
|
/// assert!(metadata.is_symlink());
|
||||||
|
/// Ok(())
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
#[unstable(feature = "is_symlink", issue = "none")]
|
||||||
|
pub fn is_symlink(&self) -> bool {
|
||||||
|
self.file_type().is_symlink()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the size of the file, in bytes, this metadata is for.
|
/// Returns the size of the file, in bytes, this metadata is for.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
|
|
@ -2588,10 +2588,9 @@ impl Path {
|
||||||
/// assert_eq!(link_path.is_symlink(), true);
|
/// assert_eq!(link_path.is_symlink(), true);
|
||||||
/// assert_eq!(link_path.exists(), false);
|
/// assert_eq!(link_path.exists(), false);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "path_ext", issue = "none")]
|
#[unstable(feature = "is_symlink", issue = "none")]
|
||||||
#[inline]
|
|
||||||
pub fn is_symlink(&self) -> bool {
|
pub fn is_symlink(&self) -> bool {
|
||||||
fs::symlink_metadata(self).is_ok()
|
fs::symlink_metadata(self).map(|m| m.is_symlink()).unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a [`Box<Path>`](Box) into a [`PathBuf`] without copying or
|
/// Converts a [`Box<Path>`](Box) into a [`PathBuf`] without copying or
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue