Implemented Path::{metadata, symlink_metadata}

yoshuawuyts-patch-1
Wouter Geraedts 5 years ago
parent 6bbfd039b1
commit 6c6106a292

@ -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<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
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
}

@ -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> {
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::Metadata> {
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<Path> for str {
fn as_ref(&self) -> &Path {
Path::new(self)
}
}
}

Loading…
Cancel
Save