Skip to content

Commit e64ad51

Browse files
committed
Cleanup warnings; format code
1 parent c8a5b00 commit e64ad51

File tree

6 files changed

+474
-410
lines changed

6 files changed

+474
-410
lines changed

src/exec.rs

+32-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22
use std::fs::{File, OpenOptions};
33
use std::io::{Read, Write};
4-
use std::os::unix::prelude::{RawFd, ExitStatusExt};
4+
use std::os::unix::prelude::{ExitStatusExt, RawFd};
55
use std::path::{Path, PathBuf};
66
use std::process::{Child, ExitStatus, Output, Stdio};
77
use std::str::Utf8Error;
@@ -224,15 +224,23 @@ impl WaitableProcess {
224224
let pid = Pid::from_raw(process.id() as i32);
225225
kill(pid, Signal::SIGHUP).unwrap();
226226
FinishedProcess {
227-
status: ProcessExit::NixStatus(WaitStatus::Signaled(pid, Signal::SIGHUP, false)),
227+
status: ProcessExit::NixStatus(WaitStatus::Signaled(
228+
pid,
229+
Signal::SIGHUP,
230+
false,
231+
)),
228232
stdout: vec![],
229233
stderr: vec![],
230234
}
231235
}
232236
OngoingProcess::Reentrant { pid, .. } => {
233237
kill(pid, Signal::SIGHUP).unwrap();
234238
FinishedProcess {
235-
status: ProcessExit::NixStatus(WaitStatus::Signaled(pid, Signal::SIGHUP, false)),
239+
status: ProcessExit::NixStatus(WaitStatus::Signaled(
240+
pid,
241+
Signal::SIGHUP,
242+
false,
243+
)),
236244
stdout: vec![],
237245
stderr: vec![],
238246
}
@@ -891,19 +899,24 @@ impl ShellContext {
891899
}
892900
}
893901
Redirect::Heredoc(fd, word) => {
894-
let mut file = tempfile::tempfile().map_err(|e| CommandExecError::BadRedirect { err: e })?; //TODO: Handle errors
902+
let mut file = tempfile::tempfile()
903+
.map_err(|e| CommandExecError::BadRedirect { err: e })?; //TODO: Handle errors
895904
for word in word {
896-
file.write_all(word.as_bytes()).map_err(|e| CommandExecError::BadRedirect { err: e })?; //TODO: Handle errors
905+
file.write_all(word.as_bytes())
906+
.map_err(|e| CommandExecError::BadRedirect { err: e })?;
907+
//TODO: Handle errors
897908
}
898909
match fd {
899910
None | Some(0) => stdin = StdioRepr::from(file),
900911
Some(1) => stdout = StdioRepr::from(file),
901912
Some(2) => stderr = StdioRepr::from(file),
902913
Some(_fd) => todo!(), // Might have to use nix::dup2?
903914
}
904-
},
915+
}
905916
Redirect::DupRead(_fd, _) => return Err(CommandExecError::UnsupportedRedirect),
906-
Redirect::DupWrite(_fd, _) => return Err(CommandExecError::UnsupportedRedirect),
917+
Redirect::DupWrite(_fd, _) => {
918+
return Err(CommandExecError::UnsupportedRedirect)
919+
}
907920
}
908921
}
909922

@@ -935,7 +948,8 @@ impl ShellContext {
935948
StdioRepr::Inherit => Some(0),
936949
StdioRepr::Null => None,
937950
StdioRepr::MakePipe => {
938-
let (read, write) = nix::unistd::pipe().map_err(|e| CommandExecError::CommandFailed { err: e.into() })?;
951+
let (read, write) = nix::unistd::pipe()
952+
.map_err(|e| CommandExecError::CommandFailed { err: e.into() })?;
939953
child_stdin = Some(write);
940954
Some(read)
941955
}
@@ -946,7 +960,8 @@ impl ShellContext {
946960
StdioRepr::Inherit => Some(1),
947961
StdioRepr::Null => None,
948962
StdioRepr::MakePipe => {
949-
let (read, write) = nix::unistd::pipe().map_err(|e| CommandExecError::CommandFailed { err: e.into() })?;
963+
let (read, write) = nix::unistd::pipe()
964+
.map_err(|e| CommandExecError::CommandFailed { err: e.into() })?;
950965
child_stdout = Some(read);
951966
Some(write)
952967
}
@@ -957,7 +972,8 @@ impl ShellContext {
957972
StdioRepr::Inherit => Some(2),
958973
StdioRepr::Null => None,
959974
StdioRepr::MakePipe => {
960-
let (read, write) = nix::unistd::pipe().map_err(|e| CommandExecError::CommandFailed { err: e.into() })?;
975+
let (read, write) = nix::unistd::pipe()
976+
.map_err(|e| CommandExecError::CommandFailed { err: e.into() })?;
961977
child_stderr = Some(read);
962978
Some(write)
963979
}
@@ -979,7 +995,8 @@ impl ShellContext {
979995
let _ = unsafe {
980996
// SAFETY: child_stdin has been take()n, so no other code might assume it exists.
981997
File::from_raw_fd(write_fd)
982-
}.write_all(&buffer); //TODO: Do I need to worry about an error here?
998+
}
999+
.write_all(&buffer); //TODO: Do I need to worry about an error here?
9831000
}
9841001
}
9851002

@@ -1200,7 +1217,9 @@ impl ShellContext {
12001217
ParameterSubstitution::Arith(_) => todo!(),
12011218
ParameterSubstitution::Default(null_is_unset, parameter, default) => {
12021219
let parameter = self.evaluate_parameter(parameter, config);
1203-
if parameter.is_empty() || (*null_is_unset && parameter.len() == 1 && parameter[0].is_empty()) {
1220+
if parameter.is_empty()
1221+
|| (*null_is_unset && parameter.len() == 1 && parameter[0].is_empty())
1222+
{
12041223
if let Some(word) = default {
12051224
self.evaluate_tl_word(word, config)?
12061225
} else {
@@ -1209,7 +1228,7 @@ impl ShellContext {
12091228
} else {
12101229
parameter
12111230
}
1212-
},
1231+
}
12131232
ParameterSubstitution::Assign(_, _, _) => todo!(),
12141233
ParameterSubstitution::Error(_, _, _) => todo!(),
12151234
ParameterSubstitution::Alternative(_, _, _) => todo!(),

0 commit comments

Comments
 (0)