@@ -15,6 +15,8 @@ use provider::Provider;
1515use remote:: { Executable , Runnable } ;
1616use std:: process;
1717use super :: { CommandProvider , CommandRunnable } ;
18+ use tokio_core:: reactor:: Handle ;
19+ use tokio_process:: CommandExt ;
1820
1921#[ derive( Clone ) ]
2022pub struct Generic ;
@@ -50,9 +52,9 @@ impl<H: Host + 'static> Provider<H> for Generic {
5052}
5153
5254impl < H : Host + ' static > CommandProvider < H > for Generic {
53- fn exec ( & self , host : & H , cmd : & str , shell : & [ String ] ) -> Box < Future < Item = CommandResult , Error = Error > > {
55+ fn exec ( & self , host : & H , handle : & Handle , cmd : & str , shell : & [ String ] ) -> Box < Future < Item = CommandResult , Error = Error > > {
5456 match host. get_type ( ) {
55- HostType :: Local ( _) => LocalGeneric :: exec ( cmd, shell) ,
57+ HostType :: Local ( _) => LocalGeneric :: exec ( handle , cmd, shell) ,
5658 HostType :: Remote ( r) => RemoteGeneric :: exec ( r, cmd, shell) ,
5759 }
5860 }
@@ -63,31 +65,27 @@ impl LocalGeneric {
6365 Box :: new ( future:: ok ( cfg ! ( unix) ) )
6466 }
6567
66- fn exec ( cmd : & str , shell : & [ String ] ) -> Box < Future < Item = CommandResult , Error = Error > > {
67- let cmd_owned = cmd. to_owned ( ) ;
68- let shell_owned = shell. to_owned ( ) ;
68+ fn exec ( handle : & Handle , cmd : & str , shell : & [ String ] ) -> Box < Future < Item = CommandResult , Error = Error > > {
69+ let cmd = cmd. to_owned ( ) ;
70+ let shell = shell. to_owned ( ) ;
71+ let ( shell, shell_args) = match shell. split_first ( ) {
72+ Some ( ( s, a) ) => ( s, a) ,
73+ None => return Box :: new ( future:: err ( "Invalid shell provided" . into ( ) ) ) ,
74+ } ;
6975
70- Box :: new ( future:: lazy ( move || -> future:: FutureResult < CommandResult , Error > {
71- let ( shell, shell_args) = match shell_owned. split_first ( ) {
72- Some ( ( s, a) ) => ( s, a) ,
73- None => return future:: err ( "Invalid shell provided" . into ( ) ) ,
74- } ;
75-
76- let out = process:: Command :: new ( shell)
77- . args ( shell_args)
78- . arg ( & cmd_owned)
79- . output ( )
80- . chain_err ( || "Command execution failed" ) ;
81- match out {
82- Ok ( output) => future:: ok ( CommandResult {
76+ Box :: new ( process:: Command :: new ( shell)
77+ . args ( shell_args)
78+ . arg ( & cmd)
79+ . output_async ( handle)
80+ . chain_err ( || "Command execution failed" )
81+ . and_then ( |output| {
82+ future:: ok ( CommandResult {
8383 success : output. status . success ( ) ,
8484 exit_code : output. status . code ( ) ,
8585 stdout : output. stdout ,
8686 stderr : output. stderr ,
87- } ) ,
88- Err ( e) => future:: err ( e) ,
89- }
90- } ) )
87+ } )
88+ } ) )
9189 }
9290}
9391
@@ -110,10 +108,10 @@ impl RemoteGeneric {
110108}
111109
112110impl Executable for GenericRunnable {
113- fn exec ( self , _: & Local ) -> Box < Future < Item = Box < Serialize > , Error = Error > > {
111+ fn exec ( self , _: & Local , handle : & Handle ) -> Box < Future < Item = Box < Serialize > , Error = Error > > {
114112 match self {
115113 GenericRunnable :: Available => Box :: new ( LocalGeneric :: available ( ) . map ( |b| Box :: new ( b) as Box < Serialize > ) ) ,
116- GenericRunnable :: Exec ( cmd, shell) => Box :: new ( LocalGeneric :: exec ( & cmd, & shell) . map ( |r| Box :: new ( r) as Box < Serialize > ) ) ,
114+ GenericRunnable :: Exec ( cmd, shell) => Box :: new ( LocalGeneric :: exec ( handle , & cmd, & shell) . map ( |r| Box :: new ( r) as Box < Serialize > ) ) ,
117115 }
118116 }
119117}
0 commit comments