1
Fork 0

Fix is_symlink() method for Path using added is_symlink() method for Metadata

This commit is contained in:
Max Wase 2021-05-27 16:04:08 +03:00
parent e1cf38fa89
commit 89c0f50b09
2 changed files with 26 additions and 3 deletions

View file

@ -1007,6 +1007,30 @@ impl Metadata {
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.
///
/// # Examples

View file

@ -2588,10 +2588,9 @@ impl Path {
/// assert_eq!(link_path.is_symlink(), true);
/// assert_eq!(link_path.exists(), false);
/// ```
#[unstable(feature = "path_ext", issue = "none")]
#[inline]
#[unstable(feature = "is_symlink", issue = "none")]
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