Read a directory on a blocking thread, returning paths of all regular files.
(dir: &std::path::Path)
| 205 | |
| 206 | /// Read a directory on a blocking thread, returning paths of all regular files. |
| 207 | async fn read_dir_sync(dir: &std::path::Path) -> std::io::Result<Vec<PathBuf>> { |
| 208 | let dir = dir.to_path_buf(); |
| 209 | tokio::task::spawn_blocking(move || { |
| 210 | let mut result = Vec::new(); |
| 211 | for entry in std::fs::read_dir(&dir)? { |
| 212 | let entry = entry?; |
| 213 | if entry.metadata()?.is_file() { |
| 214 | result.push(entry.path()); |
| 215 | } |
| 216 | } |
| 217 | Ok(result) |
| 218 | }) |
| 219 | .await |
| 220 | .map_err(|e| std::io::Error::other(format!("spawn_blocking join: {e}")))? |
| 221 | } |
| 222 | |
| 223 | /// Return the elapsed time since a file was last modified, or `None` on any error. |
| 224 | fn file_age(path: &std::path::Path, now: SystemTime) -> Option<Duration> { |
no test coverage detected