MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / read_dir

Function read_dir

euralios_std/src/fs.rs:400–436  ·  view source on GitHub ↗
(
    path: P
)

Source from the content-addressed store, hash-verified

398}
399
400pub fn read_dir<P: AsRef<Path>>(
401 path: P
402) -> Result<ReadDir, SyscallError> {
403 let path: &Path = path.as_ref();
404
405 let f = File::open(path)?;
406 let query = f.query()?;
407
408 let mut entries = match query.0["files"].as_array() {
409 Some(vec) => {
410 // Transform into a Vec of DirEntry objects
411 vec.iter().map(|obj| DirEntry{
412 name: String::from(obj["name"].as_str().unwrap_or("_bad_")),
413 meta: Metadata {
414 is_dir: false
415 }
416 }).collect()
417 }
418 _ => Vec::new()
419 };
420
421 if let Some(vec) = query.0["subdirs"].as_array() {
422 // Some directories
423 for obj in vec {
424 entries.push(DirEntry{
425 name: String::from(obj["name"].as_str().unwrap_or("_bad_")),
426 meta: Metadata {
427 is_dir: true
428 }
429 });
430 }
431 }
432
433 Ok(ReadDir{
434 entries
435 })
436}
437
438/// Delete a file
439pub fn remove_file<P: AsRef<Path>>(path: P) -> Result<(), SyscallError> {

Callers 1

lsFunction · 0.85

Calls 6

iterMethod · 0.80
as_strMethod · 0.80
openFunction · 0.70
as_refMethod · 0.45
queryMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected