diff --git a/src/fs/symlink_metadata.rs b/src/fs/symlink_metadata.rs index 6f1b9d5..7ccc596 100644 --- a/src/fs/symlink_metadata.rs +++ b/src/fs/symlink_metadata.rs @@ -1,7 +1,6 @@ -use std::path::Path; - use crate::fs::Metadata; use crate::io; +use crate::path::Path; use crate::task::blocking; /// Reads metadata for a path without following symbolic links. @@ -34,6 +33,6 @@ use crate::task::blocking; /// # Ok(()) }) } /// ``` pub async fn symlink_metadata>(path: P) -> io::Result { - let path = path.as_ref().to_owned(); + let path: std::path::PathBuf = path.as_ref().to_path_buf().into(); blocking::spawn(async move { std::fs::symlink_metadata(path) }).await } diff --git a/src/path/path.rs b/src/path/path.rs index 196935a..ffe80d9 100644 --- a/src/path/path.rs +++ b/src/path/path.rs @@ -109,6 +109,55 @@ impl Path { fs::metadata(self).await.is_ok() } + /// Queries the file system to get information about a file, directory, etc. + /// + /// This function will traverse symbolic links to query information about the + /// destination file. + /// + /// This is an alias to [`fs::metadata`]. + /// + /// [`fs::metadata`]: ../fs/fn.metadata.html + /// + /// # Examples + /// + /// ```no_run + /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # + /// use async_std::path::Path; + /// + /// let path = Path::new("/Minas/tirith"); + /// let metadata = path.metadata().await.expect("metadata call failed"); + /// println!("{:?}", metadata.file_type()); + /// # + /// # Ok(()) }) } + /// ``` + pub async fn metadata(&self) -> io::Result { + fs::metadata(self).await + } + + /// Queries the metadata about a file without following symlinks. + /// + /// This is an alias to [`fs::symlink_metadata`]. + /// + /// [`fs::symlink_metadata`]: ../fs/fn.symlink_metadata.html + /// + /// # Examples + /// + /// ```no_run + /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # + /// use async_std::path::Path; + /// + /// let path = Path::new("/Minas/tirith"); + /// let metadata = path.symlink_metadata().await.expect("symlink_metadata call failed"); + /// println!("{:?}", metadata.file_type()); + /// # + /// # Ok(()) }) } + /// ``` + pub async fn symlink_metadata(&self) -> io::Result { + fs::symlink_metadata(self).await + } + /// Directly wraps a string slice as a `Path` slice. /// /// This is a cost-free conversion. @@ -186,4 +235,4 @@ impl AsRef for str { fn as_ref(&self) -> &Path { Path::new(self) } -} \ No newline at end of file +}