about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--library/std/src/fs.rs24
-rw-r--r--library/std/src/path.rs5
2 files changed, 26 insertions, 3 deletions
diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs
index a1636e2f604..97b5e26bd0b 100644
--- a/library/std/src/fs.rs
+++ b/library/std/src/fs.rs
@@ -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
diff --git a/library/std/src/path.rs b/library/std/src/path.rs
index efee31f9915..2023a8448aa 100644
--- a/library/std/src/path.rs
+++ b/library/std/src/path.rs
@@ -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