MCPcopy Index your code
hub / github.com/endbasic/endbasic / show_dir

Function show_dir

std/src/storage/cmds.rs:58–113  ·  view source on GitHub ↗

Shows the contents of the given storage location.

(
    storage: &Storage,
    console: &mut dyn Console,
    path: &str,
    yielder: Option<Rc<RefCell<dyn Yielder>>>,
)

Source from the content-addressed store, hash-verified

56
57/// Shows the contents of the given storage location.
58async fn show_dir(
59 storage: &Storage,
60 console: &mut dyn Console,
61 path: &str,
62 yielder: Option<Rc<RefCell<dyn Yielder>>>,
63) -> io::Result<()> {
64 let canonical_path = storage.make_canonical(path)?;
65 let files = storage.enumerate(path).await?;
66
67 let format = format_description::parse("[year]-[month]-[day] [hour]:[minute]")
68 .expect("Hardcoded format must be valid");
69 let show_narrow = is_narrow(&*console);
70
71 let mut pager = Pager::new(console, yielder)?;
72 pager.print("").await?;
73 pager.print(&format!(" Directory of {}", canonical_path)).await?;
74 pager.print("").await?;
75 if show_narrow {
76 let mut total_files = 0;
77 for name in files.dirents().keys() {
78 pager.print(&format!(" {}", name,)).await?;
79 total_files += 1;
80 }
81 if total_files > 0 {
82 pager.print("").await?;
83 }
84 pager.print(&format!(" {} file(s)", total_files)).await?;
85 } else {
86 let mut total_files = 0;
87 let mut total_bytes = 0;
88 pager.print(" Modified Size Name").await?;
89 for (name, details) in files.dirents() {
90 pager
91 .print(&format!(
92 " {} {:6} {}",
93 details.date.format(&format).map_err(time_format_error_to_io_error)?,
94 details.length,
95 name,
96 ))
97 .await?;
98 total_files += 1;
99 total_bytes += details.length;
100 }
101 if total_files > 0 {
102 pager.print("").await?;
103 }
104 pager.print(&format!(" {} file(s), {} bytes", total_files, total_bytes)).await?;
105 if let (Some(disk_quota), Some(disk_free)) = (files.disk_quota(), files.disk_free()) {
106 pager
107 .print(&format!(" {} of {} bytes free", disk_free.bytes, disk_quota.bytes))
108 .await?;
109 }
110 }
111 pager.print("").await?;
112 Ok(())
113}
114
115/// Shows the mounted drives.

Callers 1

async_execMethod · 0.85

Calls 8

parseFunction · 0.85
is_narrowFunction · 0.85
make_canonicalMethod · 0.80
direntsMethod · 0.80
disk_quotaMethod · 0.80
disk_freeMethod · 0.80
enumerateMethod · 0.45
printMethod · 0.45

Tested by

no test coverage detected