mirror of https://github.com/vinc/moros.git
Fix device reading (#329)
* Avoid panic when reading device files * Skip devices in find * Fix root path in find
This commit is contained in:
parent
dab43ade5b
commit
512b60564b
|
@ -38,6 +38,7 @@ pub enum Device {
|
|||
impl From<u8> 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,
|
||||
|
|
|
@ -36,6 +36,16 @@ impl From<DirEntry> 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<Self> {
|
||||
let pathname = realpath(pathname);
|
||||
let dirname = dirname(&pathname);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue