diff --git a/src/fs/read_link.rs b/src/fs/read_link.rs index aede99b..b7ef69a 100644 --- a/src/fs/read_link.rs +++ b/src/fs/read_link.rs @@ -1,6 +1,5 @@ -use std::path::{Path, PathBuf}; - use crate::io; +use crate::path::{Path, PathBuf}; use crate::task::blocking; /// Reads a symbolic link and returns the path it points to. @@ -28,6 +27,8 @@ use crate::task::blocking; /// # Ok(()) }) } /// ``` pub async fn read_link>(path: P) -> io::Result { - let path = path.as_ref().to_owned(); - blocking::spawn(async move { std::fs::read_link(path) }).await + let path: std::path::PathBuf = path.as_ref().to_path_buf().into(); + Ok(blocking::spawn(async move { std::fs::read_link(path) }) + .await? + .into()) } diff --git a/src/path/path.rs b/src/path/path.rs index 88d7ba8..e159ca1 100644 --- a/src/path/path.rs +++ b/src/path/path.rs @@ -529,6 +529,7 @@ impl Path { /// # /// use async_std::path::Path; /// use async_std::fs; + /// use futures_util::stream::StreamExt; /// /// let path = Path::new("/laputa"); /// let mut dir = fs::read_dir(&path).await.expect("read_dir call failed"); @@ -543,6 +544,28 @@ impl Path { fs::read_dir(self).await } + /// Reads a symbolic link, returning the file that the link points to. + /// + /// This is an alias to [`fs::read_link`]. + /// + /// [`fs::read_link`]: ../fs/fn.read_link.html + /// + /// # Examples + /// + /// ```no_run + /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # + /// use async_std::path::Path; + /// + /// let path = Path::new("/laputa/sky_castle.rs"); + /// let path_link = path.read_link().await.expect("read_link call failed"); + /// # + /// # Ok(()) }) } + /// ``` + pub async fn read_link(&self) -> io::Result { + fs::read_link(self).await + } + /// Queries the metadata about a file without following symlinks. /// /// This is an alias to [`fs::symlink_metadata`].