Skip to content

Commit 2962107

Browse files
committed
top: fix panic caused by picker
1 parent dbad086 commit 2962107

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/uu/top/src/picker.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -250,23 +250,20 @@ fn command(pid: u32) -> String {
250250
let result: String = trimmed.into();
251251

252252
if cfg!(target_os = "linux") && result.is_empty() {
253-
{
254-
match PathBuf::from_str(&format!("/proc/{pid}/status")) {
255-
Ok(path) => {
256-
let file = File::open(path).unwrap();
257-
let content = read_to_string(file).unwrap();
258-
let line = content
259-
.lines()
260-
.collect::<Vec<_>>()
261-
.first()
262-
.unwrap()
263-
.split(':')
264-
.collect::<Vec<_>>();
265-
266-
line[1].trim().to_owned()
267-
}
268-
Err(_) => String::new(),
269-
}
253+
let path = PathBuf::from_str(&format!("/proc/{pid}/status")).unwrap();
254+
if let Ok(file) = File::open(path) {
255+
let content = read_to_string(file).unwrap();
256+
let line = content
257+
.lines()
258+
.collect::<Vec<_>>()
259+
.first()
260+
.unwrap()
261+
.split(':')
262+
.collect::<Vec<_>>();
263+
264+
line[1].trim().to_owned()
265+
} else {
266+
String::new()
270267
}
271268
} else {
272269
result

0 commit comments

Comments
 (0)