kaish_kernel/
backend_walker_fs.rs1use async_trait::async_trait;
7use std::path::Path;
8
9use crate::backend::{EntryInfo, KernelBackend};
10use kaish_glob::{WalkerDirEntry, WalkerError, WalkerFs};
11
12pub struct BackendWalkerFs<'a>(pub &'a dyn KernelBackend);
14
15impl WalkerDirEntry for EntryInfo {
16 fn name(&self) -> &str {
17 &self.name
18 }
19
20 fn is_dir(&self) -> bool {
21 self.is_dir
22 }
23
24 fn is_file(&self) -> bool {
25 self.is_file
26 }
27
28 fn is_symlink(&self) -> bool {
29 self.is_symlink
30 }
31}
32
33#[async_trait]
34impl WalkerFs for BackendWalkerFs<'_> {
35 type DirEntry = EntryInfo;
36
37 async fn list_dir(&self, path: &Path) -> Result<Vec<EntryInfo>, WalkerError> {
38 self.0.list(path).await.map_err(|e| WalkerError::Io(e.to_string()))
39 }
40
41 async fn read_file(&self, path: &Path) -> Result<Vec<u8>, WalkerError> {
42 self.0.read(path, None).await.map_err(|e| WalkerError::Io(e.to_string()))
43 }
44
45 async fn is_dir(&self, path: &Path) -> bool {
46 self.0.stat(path).await.is_ok_and(|info| info.is_dir)
47 }
48
49 async fn exists(&self, path: &Path) -> bool {
50 self.0.exists(path).await
51 }
52}