mirror of
https://github.com/samsonjs/agate.git
synced 2026-03-25 09:05:50 +00:00
Print directory listings in alphabetical order
This commit is contained in:
parent
bd7b542048
commit
9683146851
1 changed files with 6 additions and 3 deletions
|
|
@ -229,6 +229,7 @@ async fn list_directory<W: Write + Unpin>(stream: &mut W, path: &Path) -> Result
|
|||
log::info!("Listing directory {:?}", path);
|
||||
send_text_gemini_header(stream).await?;
|
||||
let mut entries = async_std::fs::read_dir(path).await?;
|
||||
let mut lines = vec![];
|
||||
while let Some(entry) = entries.next().await {
|
||||
let entry = entry?;
|
||||
let mut name = entry.file_name().into_string().or(Err("Non-Unicode filename"))?;
|
||||
|
|
@ -238,9 +239,11 @@ async fn list_directory<W: Write + Unpin>(stream: &mut W, path: &Path) -> Result
|
|||
if entry.file_type().await?.is_dir() {
|
||||
name += "/";
|
||||
}
|
||||
stream.write_all(b"=> ").await?;
|
||||
stream.write_all(name.as_bytes()).await?;
|
||||
stream.write_all(b"\n").await?;
|
||||
lines.push(format!("=> {}\n", name));
|
||||
}
|
||||
lines.sort();
|
||||
for line in lines {
|
||||
stream.write_all(line.as_bytes()).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue