init: read_dir test

This commit is contained in:
Mark Poliakov 2023-07-22 00:40:03 +03:00
parent be61a30034
commit 9cb3b744f7

View File

@ -1,6 +1,31 @@
#![feature(rustc_private)]
use std::os::yggdrasil::{mount, open, OpenOptions, FileMode, MountOptions};
use std::borrow::Cow;
use std::path::{Path, PathBuf};
fn ls_tree<P: AsRef<Path>>(path: P, depth: usize) -> std::io::Result<()> {
for entry in std::fs::read_dir(path)? {
let entry = entry?;
let os_filename = entry.file_name();
let filename = os_filename.to_str().unwrap();
let path = entry.path();
if filename.starts_with('.') {
continue;
}
for _ in 0..depth {
print!(" ");
}
println!("{:?}", filename);
if entry.file_type().unwrap().is_dir() {
ls_tree(path, depth + 1);
}
}
Ok(())
}
fn main() {
unsafe {
@ -17,17 +42,5 @@ fn main() {
open("/dev/ttyS0", OpenOptions::WRITE, FileMode::empty()).unwrap();
}
let stdin = std::io::stdin();
let mut buffer = String::new();
while let Ok(len) = stdin.read_line(&mut buffer) {
if len == 0 {
println!("End of file reached");
break;
}
println!("{:?}", buffer.trim());
buffer.clear();
}
loop {}
ls_tree("/", 0).ok();
}