Skip to content

Commit

Permalink
locate binary with less subprocesses
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jun 15, 2018
1 parent ba52924 commit b814825
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
- Make used shell configurable via `shellCommand` [#1536]
- Added `cleanup_tty` option for `deploy:cleanup`

### Changed
- Optimize locateBinaryPath() to create less subprocesses [#1634]

### Fixed
- Fixed that long http user name is not detected correctly [#1580]
- Fixed missing `var/sessions` in Symfony 4 shared_dirs
Expand Down Expand Up @@ -372,6 +375,7 @@
- Fixed typo3 recipe
- Fixed remove of shared dir on first deploy

[#1634]: https://github.com/deployphp/deployer/pull/1634
[#1603]: https://github.com/deployphp/deployer/issues/1603
[#1583]: https://github.com/deployphp/deployer/issues/1583
[#1580]: https://github.com/deployphp/deployer/pull/1580
Expand Down
19 changes: 4 additions & 15 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,23 +754,12 @@ function locateBinaryPath($name)
$nameEscaped = escapeshellarg($name);

// Try `command`, should cover all Bourne-like shells
if (commandExist("command")) {
return run("command -v $nameEscaped");
}

// Try `which`, should cover most other cases
if (commandExist("which")) {
return run("which $nameEscaped");
}

// Fallback to `type` command, if the rest fails
if (commandExist("type")) {
$result = run("type -p $nameEscaped");

if ($result) {
// Deal with issue when `type -p` outputs something like `type -ap` in some implementations
return trim(str_replace("$name is", "", $result));
}
$path = run("command -v $nameEscaped || which $nameEscaped || type -p $nameEscaped");
if ($path) {
// Deal with issue when `type -p` outputs something like `type -ap` in some implementations
return trim(str_replace("$name is", "", $path));
}

throw new \RuntimeException("Can't locate [$nameEscaped] - neither of [command|which|type] commands are available");
Expand Down

0 comments on commit b814825

Please sign in to comment.