Skip to content

Commit 0ba1271

Browse files
committed
uefi: process: Final Touchups
Signed-off-by: Ayush Singh <[email protected]>
1 parent 03f46e3 commit 0ba1271

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

library/std/src/sys/pal/uefi/process.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ pub enum Stdio {
4545

4646
impl Command {
4747
pub fn new(program: &OsStr) -> Command {
48-
Command {
49-
prog: program.to_os_string(),
50-
args: Vec::from([program.to_os_string()]),
51-
stdout: None,
52-
stderr: None,
53-
}
48+
Command { prog: program.to_os_string(), args: Vec::new(), stdout: None, stderr: None }
5449
}
5550

5651
pub fn arg(&mut self, arg: &OsStr) {
@@ -122,6 +117,7 @@ impl Command {
122117
pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
123118
let mut cmd = uefi_command_internal::Command::load_image(&self.prog)?;
124119

120+
/* Setup Stdout */
125121
let stdout: Option<helpers::Protocol<uefi_command_internal::PipeProtocol>> =
126122
match self.stdout.take() {
127123
Some(s) => Self::create_pipe(s),
@@ -131,7 +127,12 @@ impl Command {
131127
)
132128
.map(Some),
133129
}?;
130+
match stdout {
131+
Some(stdout) => cmd.stdout_init(stdout),
132+
None => cmd.stdout_inherit(),
133+
};
134134

135+
/* Setup Stderr */
135136
let stderr: Option<helpers::Protocol<uefi_command_internal::PipeProtocol>> =
136137
match self.stderr.take() {
137138
Some(s) => Self::create_pipe(s),
@@ -141,21 +142,15 @@ impl Command {
141142
)
142143
.map(Some),
143144
}?;
144-
145-
match stdout {
146-
Some(stdout) => cmd.stdout_init(stdout),
147-
None => cmd.stdout_inherit(),
148-
};
149145
match stderr {
150146
Some(stderr) => cmd.stderr_init(stderr),
151147
None => cmd.stderr_inherit(),
152148
};
153149

154-
if self.args.len() > 1 {
155-
let args = self.args.iter().fold(OsString::new(), |mut acc, arg| {
156-
if !acc.is_empty() {
157-
acc.push(" ");
158-
}
150+
/* No reason to set args if only program name is preset */
151+
if !self.args.is_empty() {
152+
let args = self.args.iter().fold(OsString::from(&self.prog), |mut acc, arg| {
153+
acc.push(" ");
159154
acc.push(arg);
160155
acc
161156
});
@@ -202,7 +197,11 @@ impl From<File> for Stdio {
202197
}
203198

204199
impl fmt::Debug for Command {
205-
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
200+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
201+
self.prog.fmt(f)?;
202+
for arg in &self.args {
203+
arg.fmt(f)?;
204+
}
206205
Ok(())
207206
}
208207
}
@@ -303,9 +302,11 @@ pub struct CommandArgs<'a> {
303302

304303
impl<'a> Iterator for CommandArgs<'a> {
305304
type Item = &'a OsStr;
305+
306306
fn next(&mut self) -> Option<&'a OsStr> {
307307
self.iter.next().map(|x| x.as_ref())
308308
}
309+
309310
fn size_hint(&self) -> (usize, Option<usize>) {
310311
self.iter.size_hint()
311312
}
@@ -315,6 +316,7 @@ impl<'a> ExactSizeIterator for CommandArgs<'a> {
315316
fn len(&self) -> usize {
316317
self.iter.len()
317318
}
319+
318320
fn is_empty(&self) -> bool {
319321
self.iter.is_empty()
320322
}

0 commit comments

Comments
 (0)