diff --git a/src/sys/fs/device.rs b/src/sys/fs/device.rs index efff10a..a6f060d 100644 --- a/src/sys/fs/device.rs +++ b/src/sys/fs/device.rs @@ -38,6 +38,7 @@ pub enum Device { impl From for Device { fn from(i: u8) -> Self { match i { + i if i == DeviceType::File as u8 => Device::File(File::new()), i if i == DeviceType::Console as u8 => Device::Console(Console::new()), i if i == DeviceType::Random as u8 => Device::Random(Random::new()), i if i == DeviceType::Null as u8 => Device::Null, diff --git a/src/sys/fs/file.rs b/src/sys/fs/file.rs index b72940f..d73b3d3 100644 --- a/src/sys/fs/file.rs +++ b/src/sys/fs/file.rs @@ -36,6 +36,16 @@ impl From for File { } impl File { + pub fn new() -> Self { + Self { + parent: None, + name: String::new(), + addr: 0, + size: 0, + offset:0, + } + } + pub fn create(pathname: &str) -> Option { let pathname = realpath(pathname); let dirname = dirname(&pathname); diff --git a/src/usr/find.rs b/src/usr/find.rs index 3311523..bc1180c 100644 --- a/src/usr/find.rs +++ b/src/usr/find.rs @@ -77,9 +77,15 @@ fn print_matching_lines(path: &str, pattern: &str, state: &mut PrintingState) { if let Ok(files) = fs::read_dir(path) { state.is_recursive = true; for file in files { - let file_path = format!("{}/{}", path, file.name()); + let mut file_path = path.to_string(); + if !file_path.ends_with('/') { + file_path.push('/'); + } + file_path.push_str(&file.name()); if file.is_dir() { print_matching_lines(&file_path, pattern, state); + } else if file.is_device() { + // Skip devices } else { print_matching_lines_in_file(&file_path, pattern, state); }