diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-05 17:27:07 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-05 17:27:07 -0500 |
commit | 6bfb525c90ea2fe166c812e63fa20b71b0ec113d (patch) | |
tree | 26bb1178ed631668008ae51210962fa2b24c1ac2 /src/pipeline/builtins/command.rs | |
parent | c4b5c55eba3e5782b1be575c62067dcfeac08599 (diff) | |
download | nbsh-6bfb525c90ea2fe166c812e63fa20b71b0ec113d.tar.gz nbsh-6bfb525c90ea2fe166c812e63fa20b71b0ec113d.zip |
simplify
Diffstat (limited to 'src/pipeline/builtins/command.rs')
-rw-r--r-- | src/pipeline/builtins/command.rs | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/src/pipeline/builtins/command.rs b/src/pipeline/builtins/command.rs index d65dd1c..c0fa86d 100644 --- a/src/pipeline/builtins/command.rs +++ b/src/pipeline/builtins/command.rs @@ -137,38 +137,13 @@ impl Io { pub fn apply_redirects(&mut self, redirects: &[crate::parse::Redirect]) { for redirect in redirects { - match &redirect.to { - crate::parse::RedirectTarget::Fd(fd) => { - self.fds.insert(redirect.from, self.fds[fd]); - } + let to = match &redirect.to { + crate::parse::RedirectTarget::Fd(fd) => self.fds[fd], crate::parse::RedirectTarget::File(path) => { - use nix::fcntl::OFlag; - use nix::sys::stat::Mode; - let fd = match redirect.dir { - crate::parse::Direction::In => nix::fcntl::open( - path, - OFlag::O_NOCTTY | OFlag::O_RDONLY, - Mode::empty(), - ) - .unwrap(), - crate::parse::Direction::Out => nix::fcntl::open( - path, - OFlag::O_CREAT - | OFlag::O_NOCTTY - | OFlag::O_WRONLY - | OFlag::O_TRUNC, - Mode::S_IRUSR - | Mode::S_IWUSR - | Mode::S_IRGRP - | Mode::S_IWGRP - | Mode::S_IROTH - | Mode::S_IWOTH, - ) - .unwrap(), - }; - self.fds.insert(redirect.from, fd); + redirect.dir.open(path).unwrap() } - } + }; + self.fds.insert(redirect.from, to); } } |