mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 00:13:21 +01:00
Fix handling of spaces in executable names (#13596)
# Description The original code assumed a full single-string command line could be split by space to get the original argv. # User-Facing Changes Fixes an issue where `ps` would display incomplete process name if it contained space(s). # Tests + Formatting Fixes existing code, no new coverage. Existing code doesn't seem to be covered, we could be it would be somewhat involved and the fix was simple, so didn't bother..
This commit is contained in:
parent
d5946a9667
commit
48e401834d
@ -142,31 +142,29 @@ impl ProcessInfo {
|
|||||||
|
|
||||||
/// Name of command
|
/// Name of command
|
||||||
pub fn name(&self) -> String {
|
pub fn name(&self) -> String {
|
||||||
self.command()
|
if let Ok(mut cmd) = self.curr_proc.cmdline() {
|
||||||
.split(' ')
|
if let Some(name) = cmd.first_mut() {
|
||||||
.collect::<Vec<_>>()
|
// Take over the first element and return it without extra allocations
|
||||||
.first()
|
// (String::default() is allocation-free).
|
||||||
.map(|x| x.to_string())
|
return std::mem::take(name);
|
||||||
.unwrap_or_default()
|
}
|
||||||
|
}
|
||||||
|
self.comm()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Full name of command, with arguments
|
/// Full name of command, with arguments
|
||||||
|
///
|
||||||
|
/// WARNING: As this does no escaping, this function is lossy. It's OK-ish for display purposes
|
||||||
|
/// but nothing else.
|
||||||
|
// TODO: Maybe rename this to display_command and add escaping compatible with nushell?
|
||||||
pub fn command(&self) -> String {
|
pub fn command(&self) -> String {
|
||||||
if let Ok(cmd) = &self.curr_proc.cmdline() {
|
if let Ok(cmd) = self.curr_proc.cmdline() {
|
||||||
|
// TODO: When can it successfully return empty?
|
||||||
if !cmd.is_empty() {
|
if !cmd.is_empty() {
|
||||||
cmd.join(" ").replace(['\n', '\t'], " ")
|
return cmd.join(" ").replace(['\n', '\t'], " ");
|
||||||
} else {
|
|
||||||
match self.curr_proc.stat() {
|
|
||||||
Ok(p) => p.comm,
|
|
||||||
Err(_) => "".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
match self.curr_proc.stat() {
|
|
||||||
Ok(p) => p.comm,
|
|
||||||
Err(_) => "".to_string(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.comm()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cwd(&self) -> String {
|
pub fn cwd(&self) -> String {
|
||||||
@ -228,4 +226,8 @@ impl ProcessInfo {
|
|||||||
pub fn virtual_size(&self) -> u64 {
|
pub fn virtual_size(&self) -> u64 {
|
||||||
self.curr_proc.stat().map(|p| p.vsize).unwrap_or_default()
|
self.curr_proc.stat().map(|p| p.vsize).unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn comm(&self) -> String {
|
||||||
|
self.curr_proc.stat().map(|st| st.comm).unwrap_or_default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user