Implement mutiple redirection.
Created by: chrisvittal
Add multiple redirections, that is, support for things like:
cmd <file1 <file2 ^>> err-log > output | cmd2
In current ion this doesn't work.
This change at current would be breaking as the statement:
tr 'x' 'y' | tr 'y' 'z' < file > file2
redirects file
to the first tr
command. With this change, we would redirect it to the second.
Overview
We treat a multiple redirection as it's own job. The only difference between these jobs and normal jobs is that they only read from their source(s) and then write to their sink(s).
Parsing
Alter Pipline
contain a vector of PipeItem
s. A PipeItem
consists of a Job
, a Vec<Redirection>
and a Vec<Input>
. The above statement would be parsed into two items, cmd
together with [file1, file2]
as input and [err-log, output]
as outputs, and cmd2
with no Input
s or Redirection
s
Command Generation and Redirection Setup
Added two two new variants of RefinedJob
, Cat
and Tee
, Cat
for concatenating multiple inputs, Tee
for splitting multiple outputs. Alter the generate_commands
function to return a Vec<(RefinedJob, JobKind, Vec<Redirection>, Vec<Input>)>
, then condense redirect_input
and redirect_output
into one function that takes ownership and returns a new Vec<(RefinedJob, JobKind)>
. It is here that we create the Tee
and Cat
jobs that we need and put them in the right spot in the pipeline.
Execution
Add exec_multi_in
and exec_multi_out
to handle the multiple redirections. These are fairly straightforward, they just read their sources and write to their sinks. I didn't add any extra paths to exec_job
as the new RefinedJob
kinds are always part of a pipeline.