2018-08-01 06:39:27 +02:00
|
|
|
use super::blocking_io;
|
|
|
|
|
use std::fs::{self, Metadata};
|
2019-07-11 11:05:49 -05:00
|
|
|
use std::future::Future;
|
2018-08-01 06:39:27 +02:00
|
|
|
use std::io;
|
|
|
|
|
use std::path::Path;
|
2019-07-11 11:05:49 -05:00
|
|
|
use std::pin::Pin;
|
|
|
|
|
use std::task::Context;
|
|
|
|
|
use std::task::Poll;
|
2018-08-01 06:39:27 +02:00
|
|
|
|
|
|
|
|
/// Queries the file system metadata for a path.
|
|
|
|
|
///
|
|
|
|
|
/// This is an async version of [`std::fs::symlink_metadata`][std]
|
|
|
|
|
///
|
|
|
|
|
/// [std]: https://doc.rust-lang.org/std/fs/fn.symlink_metadata.html
|
|
|
|
|
pub fn symlink_metadata<P>(path: P) -> SymlinkMetadataFuture<P>
|
|
|
|
|
where
|
|
|
|
|
P: AsRef<Path> + Send + 'static,
|
|
|
|
|
{
|
|
|
|
|
SymlinkMetadataFuture::new(path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Future returned by `symlink_metadata`.
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct SymlinkMetadataFuture<P>
|
|
|
|
|
where
|
|
|
|
|
P: AsRef<Path> + Send + 'static,
|
|
|
|
|
{
|
|
|
|
|
path: P,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<P> SymlinkMetadataFuture<P>
|
|
|
|
|
where
|
|
|
|
|
P: AsRef<Path> + Send + 'static,
|
|
|
|
|
{
|
|
|
|
|
pub(crate) fn new(path: P) -> Self {
|
|
|
|
|
Self { path }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<P> Future for SymlinkMetadataFuture<P>
|
|
|
|
|
where
|
|
|
|
|
P: AsRef<Path> + Send + 'static,
|
|
|
|
|
{
|
2019-07-11 11:05:49 -05:00
|
|
|
type Output = io::Result<Metadata>;
|
2018-08-01 06:39:27 +02:00
|
|
|
|
2019-07-11 11:05:49 -05:00
|
|
|
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
|
2018-08-01 06:39:27 +02:00
|
|
|
blocking_io(|| fs::symlink_metadata(&self.path))
|
|
|
|
|
}
|
|
|
|
|
}
|