diff options
Diffstat (limited to 'crates/shirabe/src/util')
| -rw-r--r-- | crates/shirabe/src/util/bitbucket.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe/src/util/filesystem.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/src/util/git.rs | 16 | ||||
| -rw-r--r-- | crates/shirabe/src/util/github.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/util/gitlab.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/util/hg.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/util/perforce.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe/src/util/platform.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe/src/util/process_executor.rs | 103 | ||||
| -rw-r--r-- | crates/shirabe/src/util/svn.rs | 11 |
10 files changed, 44 insertions, 118 deletions
diff --git a/crates/shirabe/src/util/bitbucket.rs b/crates/shirabe/src/util/bitbucket.rs index 26a9e65..3fc698b 100644 --- a/crates/shirabe/src/util/bitbucket.rs +++ b/crates/shirabe/src/util/bitbucket.rs @@ -83,7 +83,7 @@ impl Bitbucket { .execute( PhpMixed::from(vec!["git", "config", "bitbucket.accesstoken"]), Some(&mut output), - (), + None, ) .unwrap_or(1) == 0 diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs index 90deba1..6510638 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -121,7 +121,7 @@ impl Filesystem { .execute( PhpMixed::List(cmd.iter().map(|s| PhpMixed::String(s.clone())).collect()), Some(&mut output), - (), + None, ) .map(|n| n == 0) .unwrap_or(false); @@ -161,7 +161,7 @@ impl Filesystem { .get_process() .execute_async( PhpMixed::List(cmd.iter().map(|s| PhpMixed::String(s.clone())).collect()), - (), + None, ) .await?; @@ -499,7 +499,7 @@ impl Filesystem { "/Y".to_string(), ], &mut output, - (), + None, ); // clear stat cache because external processes aren't tracked by the php stat cache @@ -517,7 +517,7 @@ impl Filesystem { let result = self.get_process().execute_args( &["mv".to_string(), source.to_string(), target.to_string()], &mut output, - (), + None, ); // clear stat cache because external processes aren't tracked by the php stat cache @@ -951,7 +951,7 @@ impl Filesystem { Platform::realpath(target), ]; let mut output = String::new(); - if self.get_process().execute_args(&cmd, &mut output, ()) != 0 { + if self.get_process().execute_args(&cmd, &mut output, None) != 0 { return Err(IOException::new( format!( "Failed to create junction to \"{}\" at \"{}\".", diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index d66751c..f031157 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -184,7 +184,7 @@ impl Git { } else { cwd_string.clone() }; - status = this_process.execute_args(&cmd, &mut local_output, exec_cwd); + status = this_process.execute_args(&cmd, &mut local_output, exec_cwd.as_deref()); if collect_outputs { outputs.push(local_output); } @@ -217,7 +217,7 @@ impl Git { self.process.borrow_mut().execute_args( &["git".to_string(), "remote".to_string(), "-v".to_string()], &mut output, - cwd.map(|s| s.to_string()), + cwd, ); let mut m: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3( @@ -807,7 +807,7 @@ impl Git { "--git-dir".to_string(), ], &mut output, - Some(dir.to_string()), + Some(dir), ) == 0 && trim(&output, None) == "." { @@ -919,7 +919,7 @@ impl Git { if self.process.borrow_mut().execute_args( &["git".to_string(), "branch".to_string()], &mut output, - Some(dir.to_string()), + Some(dir), ) == 0 { branches = Some(output); @@ -928,7 +928,7 @@ impl Git { if self.process.borrow_mut().execute_args( &["git".to_string(), "tag".to_string()], &mut output, - Some(dir.to_string()), + Some(dir), ) == 0 { tags = Some(output); @@ -1048,7 +1048,7 @@ impl Git { "--git-dir".to_string(), ], &mut output, - Some(dir.to_string()), + Some(dir), ) == 0 && trim(&output, None) == "." { @@ -1062,7 +1062,7 @@ impl Git { format!("{}^{{commit}}", r#ref), ], &mut ignored_output, - Some(dir.to_string()), + Some(dir), ); if exit_code == 0 { return Ok(true); @@ -1123,7 +1123,7 @@ impl Git { "origin".to_string(), ], &mut output, - Some(dir.to_string()), + Some(dir), ); output_mixed = PhpMixed::String(output); } else { diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs index 204d95e..ab5efea 100644 --- a/crates/shirabe/src/util/github.rs +++ b/crates/shirabe/src/util/github.rs @@ -71,7 +71,7 @@ impl GitHub { "github.accesstoken".to_string(), ], &mut output, - (), + None, ) == 0 { self.io.borrow_mut().set_authentication( @@ -106,7 +106,7 @@ impl GitHub { if self .process .borrow_mut() - .execute_args(&["hostname".to_string()], &mut output, ()) + .execute_args(&["hostname".to_string()], &mut output, None) == 0 { note += &format!(" on {}", output.trim()); diff --git a/crates/shirabe/src/util/gitlab.rs b/crates/shirabe/src/util/gitlab.rs index 71ff7e3..a71c231 100644 --- a/crates/shirabe/src/util/gitlab.rs +++ b/crates/shirabe/src/util/gitlab.rs @@ -75,7 +75,7 @@ impl GitLab { "gitlab.accesstoken".to_string(), ], &mut output, - (), + None, ) == 0 { self.io.borrow_mut().set_authentication( @@ -96,7 +96,7 @@ impl GitLab { "gitlab.deploytoken.user".to_string(), ], &mut token_user, - (), + None, ) == 0 && self.process.borrow_mut().execute_args( &[ @@ -105,7 +105,7 @@ impl GitLab { "gitlab.deploytoken.token".to_string(), ], &mut token_password, - (), + None, ) == 0 { self.io.borrow_mut().set_authentication( diff --git a/crates/shirabe/src/util/hg.rs b/crates/shirabe/src/util/hg.rs index 7fbf125..0caf3ab 100644 --- a/crates/shirabe/src/util/hg.rs +++ b/crates/shirabe/src/util/hg.rs @@ -50,7 +50,7 @@ impl Hg { if self .process .borrow_mut() - .execute_args(&command, &mut ignored_output, cwd.clone()) + .execute_args(&command, &mut ignored_output, cwd.as_deref()) == 0 { return Ok(()); @@ -109,7 +109,7 @@ impl Hg { if self .process .borrow_mut() - .execute_args(&command, &mut ignored_output, cwd) + .execute_args(&command, &mut ignored_output, cwd.as_deref()) == 0 { return Ok(()); @@ -150,7 +150,7 @@ impl Hg { if process.borrow_mut().execute_args( &["hg".to_string(), "--version".to_string()], &mut output, - (), + None, ) == 0 && let Some(matches) = Preg::is_match_with_indexed_captures( r"/^.+? (\d+(?:\.\d+)+)(?:\+.*?)?\)?\r?\n/", diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs index 7ca3f26..11d8cc5 100644 --- a/crates/shirabe/src/util/perforce.rs +++ b/crates/shirabe/src/util/perforce.rs @@ -167,7 +167,7 @@ impl Perforce { }; self.process .borrow_mut() - .execute_args(&cmd_vec, &mut self.command_result, ()) + .execute_args(&cmd_vec, &mut self.command_result, None) } pub fn get_client(&mut self) -> String { diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index 442b4d9..72fe5f9 100644 --- a/crates/shirabe/src/util/platform.rs +++ b/crates/shirabe/src/util/platform.rs @@ -381,7 +381,7 @@ impl Platform { let mut process = ProcessExecutor::new(None); let mut output = String::new(); let result: Result<()> = (|| { - if process.execute_args(&["lsmod".to_string()], &mut output, ()) == 0 + if process.execute_args(&["lsmod".to_string()], &mut output, None) == 0 && shirabe_php_shim::str_contains(&output, "vboxguest") { *cached = Some(true); diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs index 1f15795..842e934 100644 --- a/crates/shirabe/src/util/process_executor.rs +++ b/crates/shirabe/src/util/process_executor.rs @@ -110,31 +110,22 @@ impl ProcessExecutor { /// if a callable is passed it will be used as output handler /// @param null|string $cwd the working directory /// @return int statuscode - pub fn execute<'o, C, O, W>(&mut self, command: C, output: O, cwd: W) -> Result<i64> + pub fn execute<'o, C, O>(&mut self, command: C, output: O, cwd: Option<&str>) -> Result<i64> where C: IntoExecCommand, O: IntoExecOutput<'o>, - W: IntoExecCwd, { let command = command.into_exec_command(); let mut output = output.into_exec_output(); - let cwd_storage; - let cwd_ref: Option<&str> = match cwd.into_exec_cwd() { - Some(s) => { - cwd_storage = s; - Some(cwd_storage.as_str()) - } - None => None, - }; // PHP: func_num_args() > 1 let has_output_arg = output.has_output(); let rc = if has_output_arg { let mut buf = PhpMixed::Null; - let result = self.do_execute(command, cwd_ref, false, Some(&mut buf))?; + let result = self.do_execute(command, cwd, false, Some(&mut buf))?; output.write_back(buf); result } else { - self.do_execute(command, cwd_ref, false, None)? + self.do_execute(command, cwd, false, None)? }; Ok(rc) } @@ -142,10 +133,12 @@ impl ProcessExecutor { /// Convenience wrapper used by phase-A code that calls /// `process.execute(&[String], &mut String, Option<&str>) == 0`. /// Forwards to `execute`, returning the status code (0 on Err for compatibility). - pub fn execute_args<W>(&mut self, command: &[String], output: &mut String, cwd: W) -> i64 - where - W: IntoExecCwd, - { + pub fn execute_args( + &mut self, + command: &[String], + output: &mut String, + cwd: Option<&str>, + ) -> i64 { let cmd = PhpMixed::List( command .iter() @@ -153,39 +146,22 @@ impl ProcessExecutor { .collect(), ); let mut buf = PhpMixed::String(String::new()); - let cwd_storage; - let cwd_ref: Option<&str> = match cwd.into_exec_cwd() { - Some(s) => { - cwd_storage = s; - Some(cwd_storage.as_str()) - } - None => None, - }; - let rc = self.execute(cmd, Some(&mut buf), cwd_ref).unwrap_or(1); + let rc = self.execute(cmd, Some(&mut buf), cwd).unwrap_or(1); *output = buf.as_string().unwrap_or("").to_string(); rc } /// runs a process on the commandline in TTY mode - pub fn execute_tty<C, W>(&mut self, command: C, cwd: W) -> Result<i64> + pub fn execute_tty<C>(&mut self, command: C, cwd: Option<&str>) -> Result<i64> where C: IntoExecCommand, - W: IntoExecCwd, { let command = command.into_exec_command(); - let cwd_storage; - let cwd_ref: Option<&str> = match cwd.into_exec_cwd() { - Some(s) => { - cwd_storage = s; - Some(cwd_storage.as_str()) - } - None => None, - }; if Platform::is_tty(None) { - return self.do_execute(command, cwd_ref, true, None); + return self.do_execute(command, cwd, true, None); } - self.do_execute(command, cwd_ref, false, None) + self.do_execute(command, cwd, false, None) } /// @param string|non-empty-list<string> $command @@ -377,13 +353,11 @@ impl ProcessExecutor { } /// starts a process on the commandline in async mode - pub async fn execute_async<C, W>(&mut self, command: C, cwd: W) -> Result<Process> + pub async fn execute_async<C>(&mut self, command: C, cwd: Option<&str>) -> Result<Process> where C: IntoExecCommand, - W: IntoExecCwd, { let command = command.into_exec_command(); - let cwd_opt = cwd.into_exec_cwd(); if !self.allow_async { return Err(LogicException { message: "You must use the ProcessExecutor instance which is part of a Composer\\Loop instance to be able to run async processes".to_string(), @@ -398,7 +372,7 @@ impl ProcessExecutor { id, status: Self::STATUS_QUEUED, command, - cwd: cwd_opt, + cwd: cwd.map(ToOwned::to_owned), process: None, exception: None, }; @@ -987,53 +961,6 @@ impl<'a> IntoExecOutput<'a> for &'a mut String { } } -/// Phase B helper trait: convert various cwd argument forms into `Option<String>`. -pub trait IntoExecCwd { - fn into_exec_cwd(self) -> Option<String>; -} - -impl IntoExecCwd for () { - fn into_exec_cwd(self) -> Option<String> { - None - } -} - -impl IntoExecCwd for Option<&str> { - fn into_exec_cwd(self) -> Option<String> { - self.map(|s| s.to_string()) - } -} - -impl IntoExecCwd for Option<String> { - fn into_exec_cwd(self) -> Option<String> { - self - } -} - -impl IntoExecCwd for Option<&String> { - fn into_exec_cwd(self) -> Option<String> { - self.cloned() - } -} - -impl IntoExecCwd for &str { - fn into_exec_cwd(self) -> Option<String> { - Some(self.to_string()) - } -} - -impl IntoExecCwd for String { - fn into_exec_cwd(self) -> Option<String> { - Some(self) - } -} - -impl IntoExecCwd for &String { - fn into_exec_cwd(self) -> Option<String> { - Some(self.clone()) - } -} - /// Phase B helper: accept either `i64` or `PhpMixed` for `set_timeout`. pub trait ToTimeoutSeconds { fn to_timeout_seconds(self) -> i64; diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs index 0a3daf3..84e5760 100644 --- a/crates/shirabe/src/util/svn.rs +++ b/crates/shirabe/src/util/svn.rs @@ -165,11 +165,10 @@ impl Svn { // TODO(phase-c): pass the filtering handler above to process.execute once the callback // model lands; for now a plain buffer is used and the output filtering is skipped. let mut handler_output = String::new(); - let status = self.process.borrow_mut().execute_args( - &command, - &mut handler_output, - cwd.map(String::from), - ); + let status = self + .process + .borrow_mut() + .execute_args(&command, &mut handler_output, cwd); if 0 == status { return Ok(output); } @@ -455,7 +454,7 @@ impl Svn { if 0 == self.process.borrow_mut().execute_args( &["svn".to_string(), "--version".to_string()], &mut output, - (), + None, ) { let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3(r"{(\d+(?:\.\d+)+)}", &output, Some(&mut matches)) { |
