Skip to content

Commit

Permalink
uefi: process: Final Touchups
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
  • Loading branch information
Ayush1325 committed Mar 29, 2024
1 parent 03f46e3 commit 0ba1271
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions library/std/src/sys/pal/uefi/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ pub enum Stdio {

impl Command {
pub fn new(program: &OsStr) -> Command {
Command {
prog: program.to_os_string(),
args: Vec::from([program.to_os_string()]),
stdout: None,
stderr: None,
}
Command { prog: program.to_os_string(), args: Vec::new(), stdout: None, stderr: None }
}

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

/* Setup Stdout */
let stdout: Option<helpers::Protocol<uefi_command_internal::PipeProtocol>> =
match self.stdout.take() {
Some(s) => Self::create_pipe(s),
Expand All @@ -131,7 +127,12 @@ impl Command {
)
.map(Some),
}?;
match stdout {
Some(stdout) => cmd.stdout_init(stdout),
None => cmd.stdout_inherit(),
};

/* Setup Stderr */
let stderr: Option<helpers::Protocol<uefi_command_internal::PipeProtocol>> =
match self.stderr.take() {
Some(s) => Self::create_pipe(s),
Expand All @@ -141,21 +142,15 @@ impl Command {
)
.map(Some),
}?;

match stdout {
Some(stdout) => cmd.stdout_init(stdout),
None => cmd.stdout_inherit(),
};
match stderr {
Some(stderr) => cmd.stderr_init(stderr),
None => cmd.stderr_inherit(),
};

if self.args.len() > 1 {
let args = self.args.iter().fold(OsString::new(), |mut acc, arg| {
if !acc.is_empty() {
acc.push(" ");
}
/* No reason to set args if only program name is preset */
if !self.args.is_empty() {
let args = self.args.iter().fold(OsString::from(&self.prog), |mut acc, arg| {
acc.push(" ");
acc.push(arg);
acc
});
Expand Down Expand Up @@ -202,7 +197,11 @@ impl From<File> for Stdio {
}

impl fmt::Debug for Command {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.prog.fmt(f)?;
for arg in &self.args {
arg.fmt(f)?;
}
Ok(())
}
}
Expand Down Expand Up @@ -303,9 +302,11 @@ pub struct CommandArgs<'a> {

impl<'a> Iterator for CommandArgs<'a> {
type Item = &'a OsStr;

fn next(&mut self) -> Option<&'a OsStr> {
self.iter.next().map(|x| x.as_ref())
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
Expand All @@ -315,6 +316,7 @@ impl<'a> ExactSizeIterator for CommandArgs<'a> {
fn len(&self) -> usize {
self.iter.len()
}

fn is_empty(&self) -> bool {
self.iter.is_empty()
}
Expand Down

0 comments on commit 0ba1271

Please sign in to comment.