Skip to content

Commit

Permalink
bug #26886 Don't assume that file binary exists on *nix OS (teohhanhui)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.7 branch.

Discussion
----------

Don't assume that file binary exists on *nix OS

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

Certain lightweight distributions such as Alpine Linux (popular for smaller Docker images) do not include it by default.

Commits
-------

e2c1f24 Don't assume that file binary exists on *nix OS
  • Loading branch information
fabpot committed Apr 17, 2018
2 parents d17d38d + e2c1f24 commit b0410d4
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,21 @@ public function __construct($cmd = 'file -b --mime %s 2>/dev/null')
*/
public static function isSupported()
{
return '\\' !== DIRECTORY_SEPARATOR && function_exists('passthru') && function_exists('escapeshellarg');
static $supported = null;

if (null !== $supported) {
return $supported;
}

if ('\\' === DIRECTORY_SEPARATOR || !function_exists('passthru') || !function_exists('escapeshellarg')) {
return $supported = false;
}

ob_start();
passthru('command -v file', $exitStatus);
$binPath = trim(ob_get_clean());

return $supported = 0 === $exitStatus && '' !== $binPath;
}

/**
Expand Down

0 comments on commit b0410d4

Please sign in to comment.