uefi: process: Final Touchups · model-checking/verify-rust-std@c6cb67c (original) (raw)

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

`

35

35

`pub stderr: Option,

`

36

36

`}

`

37

37

``

38

``

`-

// 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.

`

40

38

`pub enum Stdio {

`

41

39

`Inherit,

`

42

40

`Null,

`

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

`

45

43

``

46

44

`impl Command {

`

47

45

`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 }

`

54

47

`}

`

55

48

``

56

49

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

`

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

`

122

115

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

`

123

116

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

`

124

117

``

``

118

`+

/* Setup Stdout */

`

125

119

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

`

126

120

`match self.stdout.take() {

`

127

121

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

`

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

`

131

125

`)

`

132

126

`.map(Some),

`

133

127

`}?;

`

``

128

`+

match stdout {

`

``

129

`+

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

`

``

130

`+

None => cmd.stdout_inherit(),

`

``

131

`+

};

`

134

132

``

``

133

`+

/* Setup Stderr */

`

135

134

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

`

136

135

`match self.stderr.take() {

`

137

136

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

`

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

`

141

140

`)

`

142

141

`.map(Some),

`

143

142

`}?;

`

144

``

-

145

``

`-

match stdout {

`

146

``

`-

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

`

147

``

`-

None => cmd.stdout_inherit(),

`

148

``

`-

};

`

149

143

`match stderr {

`

150

144

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

`

151

145

`None => cmd.stderr_inherit(),

`

152

146

`};

`

153

147

``

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

``

`-

}

`

``

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(" ");

`

159

152

` acc.push(arg);

`

160

153

` acc

`

161

154

`});

`

`@@ -202,7 +195,11 @@ impl From for Stdio {

`

202

195

`}

`

203

196

``

204

197

`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

`+

}

`

206

203

`Ok(())

`

207

204

`}

`

208

205

`}

`

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

`

303

300

``

304

301

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

`

305

302

`type Item = &'a OsStr;

`

``

303

+

306

304

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

`

307

305

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

`

308

306

`}

`

``

307

+

309

308

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

`

310

309

`self.iter.size_hint()

`

311

310

`}

`

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

`

315

314

`fn len(&self) -> usize {

`

316

315

`self.iter.len()

`

317

316

`}

`

``

317

+

318

318

`fn is_empty(&self) -> bool {

`

319

319

`self.iter.is_empty()

`

320

320

`}

`