Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0410d4

Browse files
committed
bug #26886 Don't assume that file binary exists on *nix OS (teohhanhui)
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
2 parents d17d38d + e2c1f24 commit b0410d4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,21 @@ public function __construct($cmd = 'file -b --mime %s 2>/dev/null')
4343
*/
4444
public static function isSupported()
4545
{
46-
return '\\' !== DIRECTORY_SEPARATOR && function_exists('passthru') && function_exists('escapeshellarg');
46+
static $supported = null;
47+
48+
if (null !== $supported) {
49+
return $supported;
50+
}
51+
52+
if ('\\' === DIRECTORY_SEPARATOR || !function_exists('passthru') || !function_exists('escapeshellarg')) {
53+
return $supported = false;
54+
}
55+
56+
ob_start();
57+
passthru('command -v file', $exitStatus);
58+
$binPath = trim(ob_get_clean());
59+
60+
return $supported = 0 === $exitStatus && '' !== $binPath;
4761
}
4862

4963
/**

0 commit comments

Comments
 (0)