1 use crate::fs::asyncify; 2 3 use std::fs::Metadata; 4 use std::io; 5 use std::path::Path; 6 7 /// Given a path, queries the file system to get information about a file, 8 /// directory, etc. 9 /// 10 /// This is an async version of [`std::fs::metadata`][std] 11 /// 12 /// This function will traverse symbolic links to query information about the 13 /// destination file. 14 /// 15 /// # Platform-specific behavior 16 /// 17 /// This function currently corresponds to the `stat` function on Unix and the 18 /// `GetFileAttributesEx` function on Windows. Note that, this [may change in 19 /// the future][changes]. 20 /// 21 /// [std]: std::fs::metadata 22 /// [changes]: https://doc.rust-lang.org/std/io/index.html#platform-specific-behavior 23 /// 24 /// # Errors 25 /// 26 /// This function will return an error in the following situations, but is not 27 /// limited to just these cases: 28 /// 29 /// * The user lacks permissions to perform `metadata` call on `path`. 30 /// * `path` does not exist. 31 /// 32 /// # Examples 33 /// 34 /// ```rust,no_run 35 /// use tokio::fs; 36 /// 37 /// #[tokio::main] 38 /// async fn main() -> std::io::Result<()> { 39 /// let attr = fs::metadata("/some/file/path.txt").await?; 40 /// // inspect attr ... 41 /// Ok(()) 42 /// } 43 /// ``` metadata(path: impl AsRef<Path>) -> io::Result<Metadata>44pub async fn metadata(path: impl AsRef<Path>) -> io::Result<Metadata> { 45 let path = path.as_ref().to_owned(); 46 asyncify(|| std::fs::metadata(path)).await 47 } 48