Skip to content

Commit b8c6b0c

Browse files
committed
fix clippy errors again
1 parent b11c169 commit b8c6b0c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

applications/shell/src/lib.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ impl Shell {
14291429

14301430
let file_path = args[0];
14311431
self.less = true;
1432-
self.get_content_string(file_path.to_string());
1432+
let _ = self.get_content_string(file_path.to_string());
14331433
self.terminal.lock().clear();
14341434
self.clear_cmdline(false)?;
14351435
self.parse_content();
@@ -1461,6 +1461,7 @@ impl Shell {
14611461
None => return Err("failed to get the byte indices of the last line")
14621462
};
14631463

1464+
info!("{}", self.content.len() - 1);
14641465
self.terminal.lock().clear();
14651466
self.terminal.lock().print_to_terminal(
14661467
self.content[start_indices.start..end_indices.end].to_string()
@@ -1498,16 +1499,13 @@ impl Shell {
14981499
previous_char = c;
14991500
}
15001501
self.map.insert(cur_line_num, LineSlice{ start: line_start_idx, end: self.content.len() });
1501-
1502-
for (line_num, line_slice) in &self.map {
1503-
self.terminal.lock().print_to_terminal(format!("Line {}: start = {}, end = {}\n", line_num, line_slice.start, line_slice.end).to_string());
1504-
}
15051502
}
15061503

15071504
/// Stores the entire file as a string to be parsed by 'less' operation
1508-
fn get_content_string(&mut self, file_path: String) {
1505+
fn get_content_string(&mut self, file_path: String) -> Result<String, String>{
15091506
let Ok(curr_wd) = task::with_current_task(|t| t.get_env().lock().working_dir.clone()) else {
15101507
self.terminal.lock().print_to_terminal("failed to get current task".to_string());
1508+
return Err("failed to get current task".to_string());
15111509
};
15121510

15131511
let curr_dir = self.env.lock().working_dir.lock().get_absolute_path();
@@ -1522,6 +1520,7 @@ impl Shell {
15221520
// Checks if it is a directory
15231521
FileOrDir::Dir(directory) => {
15241522
self.terminal.lock().print_to_terminal(format!("{:?} a directory, cannot 'less' non-files.", directory.lock().get_name()));
1523+
return Err(format!("Failed to read directory").to_string())
15251524
}
15261525
// Checks if it is a file and reads it into a utf8 string
15271526
FileOrDir::File(file) => {
@@ -1530,20 +1529,24 @@ impl Shell {
15301529
let mut string_slice_as_bytes = vec![0; file_size];
15311530
if let Err(_e) = file_locked.read_at(&mut string_slice_as_bytes, 0) {
15321531
self.terminal.lock().print_to_terminal("Failed to read error".to_string());
1532+
return Err(format!("Failed to read file"));
15331533
}
15341534
let read_string = match str::from_utf8(&string_slice_as_bytes) {
15351535
Ok(string_slice) => string_slice,
15361536
Err(_utf8_err) => {
15371537
self.terminal.lock().print_to_terminal("File was not a printable UTF-8 text file".to_string());
1538+
return Err(format!("File was not a printable UTF-8 text file").to_string());
15381539
}
15391540
};
15401541
// Stores the content of the file as a string
15411542
self.content = read_string.to_string();
1543+
Ok(read_string.to_string())
15421544
}
15431545
}
15441546
},
15451547
None => {
15461548
self.terminal.lock().print_to_terminal(format!("Path not found: {}\n", path).to_string());
1549+
return Err(format!("File was not found").to_string());
15471550
}
15481551
}
15491552
}

0 commit comments

Comments
 (0)