Skip to content

Commit 514c854

Browse files
1 parent 8b7e172 commit 514c854

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Source/RPC/CocoonService.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,15 @@ impl CocoonService for CocoonServiceImpl {
450450
let Path = Params.as_str().or_else(|| Params.get("path").and_then(|V| V.as_str())).unwrap_or("");
451451
match tokio::fs::read_dir(Path).await {
452452
Ok(mut Entries) => {
453-
let mut Names:Vec<String> = Vec::new();
453+
// Return [{name, type}] where type 1=File 2=Directory
454+
let mut Items:Vec<serde_json::Value> = Vec::new();
454455
while let Ok(Some(Entry)) = Entries.next_entry().await {
455456
if let Some(Name) = Entry.file_name().to_str() {
456-
Names.push(Name.to_string());
457+
let IsDir = Entry.file_type().await.map(|T| T.is_dir()).unwrap_or(false);
458+
Items.push(json!({ "name": Name, "type": if IsDir { 2u32 } else { 1u32 } }));
457459
}
458460
}
459-
Ok(OkResponse(RequestId, &Names))
461+
Ok(OkResponse(RequestId, &Items))
460462
},
461463
Err(Error) => Ok(ErrResponse(RequestId, -32000, format!("fs.listDir: {}", Error))),
462464
}

0 commit comments

Comments
 (0)