Skip to content

Commit a87c3d1

Browse files
authored
Do not skip unprintable processes (#23)
When printing a process result the corresponding file should be valid, since a result was successfully generated.
1 parent ad27bb9 commit a87c3d1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/main.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use sysinfo::{
2020
PidExt, ProcessExt, ProcessRefreshKind, RefreshKind, System, SystemExt,
2121
};
2222

23-
use std::path::{Path, PathBuf};
23+
use std::ffi::OsStr;
24+
use std::path::Path;
2425
use std::{env, fmt, fs, process};
2526

2627
#[cfg(feature = "color")]
@@ -97,16 +98,16 @@ fn print_process_results(processes: &Processes, settings: &output::Settings) {
9798
output::Format::Text => {
9899
for process in &processes.processes {
99100
for binary in &process.binary {
100-
if let Some(file_name) =
101-
PathBuf::from(&binary.file).file_name()
102-
{
103-
if let Some(name) = file_name.to_str() {
104-
println!(
105-
"{}({})\n \u{21aa} {}",
106-
name, process.pid, binary
107-
);
108-
}
109-
}
101+
println!(
102+
"{}({})\n \u{21aa} {}",
103+
binary
104+
.file
105+
.file_name()
106+
.unwrap_or_else(|| OsStr::new("n/a"))
107+
.to_string_lossy(),
108+
process.pid,
109+
binary
110+
);
110111
}
111112
#[cfg(all(
112113
feature = "maps",

0 commit comments

Comments
 (0)