@ -39,17 +39,17 @@ fn dup_file<F: ?Sized + AsRawFd>(file: &F) -> io::Result<memfile::RawFile>
Ok ( memfile ::RawFile ::take_ownership_of_unchecked ( fd ) )
}
fn run_stdin < I > ( file : impl Into < fs ::File > , filename : impl AsRef < OsStr > , args : I ) -> io ::Result < process ::Child >
fn run_stdin < I > ( file : Option < impl Into < fs ::File > > , filename : impl AsRef < OsStr > , args : I ) -> io ::Result < process ::Child >
where I : IntoIterator < Item = OsString > ,
{
let file = {
let mut file : fs ::File = file . into( ) ;
let mut file : Option < fs ::File > = file . map( Into :: into) ;
//TODO: Do we need to fcntl() this to make it (the fd) RW?
file
} ;
let child = process ::Command ::new ( filename )
. args ( args )
. stdin ( process::Stdio ::from ( file ) )
. stdin ( file. map ( | file | process::Stdio ::from ( file ) ) . unwrap_or_else ( | | process ::Stdio ::inherit ( ) ) )
. stdout ( process ::Stdio ::inherit ( ) )
. spawn ( ) ? ;
@ -71,10 +71,10 @@ pub fn run_single<F: ?Sized + AsRawFd>(file: &F, opt: args::ExecMode) -> io::Res
match opt {
args ::ExecMode ::Positional { command , args } = > {
todo! ( "implement this with `proc_file(&file)`" )
run_stdin ( None ::< fs ::File > , command , args . into_iter ( ) . map ( move | x | x . unwrap_or_else ( | | proc_file ( & input ) . into ( ) ) ) )
} ,
args ::ExecMode ::Stdin { command , args } = > {
run_stdin ( input , command , args )
run_stdin ( Some ( input ) , command , args )
}
}
}
@ -83,13 +83,29 @@ pub fn run_single<F: ?Sized + AsRawFd>(file: &F, opt: args::ExecMode) -> io::Res
///
/// # Returns
/// An iterator of each (possibly running) spawned child, or the error that occoured when trying to spawn that child from the `exec` option in `opt`.
pub fn spawn_from < F : ? Sized + AsRawFd > ( file : & F , opt : Options ) -> i o::Result < i mpl IntoIterator < Item = io ::Result < process ::Child > + ' static > >
pub fn spawn_from < ' a , F : ? Sized + AsRawFd > ( file : & ' a F , opt : Options ) -> i mpl IntoIterator < Item = io ::Result < process ::Child > > + ' a
{
todo! ( "Loop through `opt.into_exec()`, map the call to `|x| run_single(file, x)`, and return that iterator" )
opt . into_opt_exec ( ) . map ( | x | run_single ( file , x ) )
//todo!("Loop through `opt.into_exec()`, map the call to `|x| run_single(file, x)`, and return that iterator")
}
/// Spawn all `-exec/{}` commands and wait for all children to complete.
///
/// # Returns
/// An iterator of the result of spawning each child and its exit status.
#[ inline ]
pub fn spawn_from < F : ? Sized + AsRawFd > ( file : & F , opt : Options ) -> io ::Result < impl IntoIterator < Item = io ::Result < i32 > + ' static > >
pub fn spawn_from _sync < ' a , F : ? Sized + AsRawFd > ( file : & ' a F , opt : Options ) -> i mpl IntoIterator < Item = io ::Result < i32 > > + ' a
{
todo! ( "Map `spawn_from(...)` and wait for each child to terminate concurrently. Then return an iterator or the return codes or spawning errors for that now terminated child." )
spawn_from ( file , opt ) . into_iter ( ) . map ( move | child | -> io ::Result < _ > {
match child {
Ok ( mut child ) = > {
Ok ( child . wait ( ) ? . code ( ) . unwrap_or ( - 1 ) )
} ,
Err ( err ) = > {
if_trace ! ( error ! ( "Failed to spawn child: {err}" ) ) ;
Err ( err )
}
}
} )
//todo!("Map `spawn_from(...)` and wait for each child to terminate concurrently. Then return an iterator or the return codes or spawning errors for that now terminated child.")
}