uefi: process: Final Touchups · model-checking/verify-rust-std@c6cb67c

@@ -35,8 +35,6 @@ pub struct StdioPipes {

3535

pub stderr: Option<AnonPipe>,

3636

}

373738-

// FIXME: This should be a unit struct, so we can always construct it

39-

// The value here should be never used, since we cannot spawn processes.

4038

pub enum Stdio {

4139

Inherit,

4240

Null,

@@ -45,12 +43,7 @@ pub enum Stdio {

45434644

impl Command {

4745

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-

}

46+

Command { prog: program.to_os_string(), args: Vec::new(), stdout: None, stderr: None }

5447

}

55485649

pub fn arg(&mut self, arg: &OsStr) {

@@ -122,6 +115,7 @@ impl Command {

122115

pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {

123116

let mut cmd = uefi_command_internal::Command::load_image(&self.prog)?;

124117118+

/* Setup Stdout */

125119

let stdout: Option<helpers::Protocol<uefi_command_internal::PipeProtocol>> =

126120

match self.stdout.take() {

127121

Some(s) => Self::create_pipe(s),

@@ -131,7 +125,12 @@ impl Command {

131125

)

132126

.map(Some),

133127

}?;

128+

match stdout {

129+

Some(stdout) => cmd.stdout_init(stdout),

130+

None => cmd.stdout_inherit(),

131+

};

134132133+

/* Setup Stderr */

135134

let stderr: Option<helpers::Protocol<uefi_command_internal::PipeProtocol>> =

136135

match self.stderr.take() {

137136

Some(s) => Self::create_pipe(s),

@@ -141,21 +140,15 @@ impl Command {

141140

)

142141

.map(Some),

143142

}?;

144-145-

match stdout {

146-

Some(stdout) => cmd.stdout_init(stdout),

147-

None => cmd.stdout_inherit(),

148-

};

149143

match stderr {

150144

Some(stderr) => cmd.stderr_init(stderr),

151145

None => cmd.stderr_inherit(),

152146

};

153147154-

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-

}

148+

/* No reason to set args if only program name is preset */

149+

if !self.args.is_empty() {

150+

let args = self.args.iter().fold(OsString::from(&self.prog), |mut acc, arg| {

151+

acc.push(" ");

159152

acc.push(arg);

160153

acc

161154

});

@@ -202,7 +195,11 @@ impl From<File> for Stdio {

202195

}

203196204197

impl fmt::Debug for Command {

205-

fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {

198+

fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

199+

self.prog.fmt(f)?;

200+

for arg in &self.args {

201+

arg.fmt(f)?;

202+

}

206203

Ok(())

207204

}

208205

}

@@ -303,9 +300,11 @@ pub struct CommandArgs<'a> {

303300304301

impl<'a> Iterator for CommandArgs<'a> {

305302

type Item = &'a OsStr;

303+306304

fn next(&mut self) -> Option<&'a OsStr> {

307305

self.iter.next().map(|x| x.as_ref())

308306

}

307+309308

fn size_hint(&self) -> (usize, Option<usize>) {

310309

self.iter.size_hint()

311310

}

@@ -315,6 +314,7 @@ impl<'a> ExactSizeIterator for CommandArgs<'a> {

315314

fn len(&self) -> usize {

316315

self.iter.len()

317316

}

317+318318

fn is_empty(&self) -> bool {

319319

self.iter.is_empty()

320320

}