forked from mirror/async-std
Implemented Path::{metadata, symlink_metadata}
This commit is contained in:
parent
6bbfd039b1
commit
6c6106a292
2 changed files with 52 additions and 4 deletions
|
@ -1,7 +1,6 @@
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use crate::fs::Metadata;
|
use crate::fs::Metadata;
|
||||||
use crate::io;
|
use crate::io;
|
||||||
|
use crate::path::Path;
|
||||||
use crate::task::blocking;
|
use crate::task::blocking;
|
||||||
|
|
||||||
/// Reads metadata for a path without following symbolic links.
|
/// Reads metadata for a path without following symbolic links.
|
||||||
|
@ -34,6 +33,6 @@ use crate::task::blocking;
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
|
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
|
blocking::spawn(async move { std::fs::symlink_metadata(path) }).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,55 @@ impl Path {
|
||||||
fs::metadata(self).await.is_ok()
|
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.
|
/// Directly wraps a string slice as a `Path` slice.
|
||||||
///
|
///
|
||||||
/// This is a cost-free conversion.
|
/// This is a cost-free conversion.
|
||||||
|
@ -186,4 +235,4 @@ impl AsRef<Path> for str {
|
||||||
fn as_ref(&self) -> &Path {
|
fn as_ref(&self) -> &Path {
|
||||||
Path::new(self)
|
Path::new(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue