8000 Don't assume that file binary exists on *nix OS · symfony/symfony@8b1c680 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8b1c680

Browse files
committed
Don't assume that file binary exists on *nix OS
Certain lightweight distributions such as Alpine Linux (popular for smaller Docker images) do not include it by default.
1 parent 1067468 commit 8b1c680

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ 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+
return '\\' !== DIRECTORY_SEPARATOR && function_exists('passthru') && function_exists('escapeshellarg') && static::hasFileBinary();
4747
}
4848

4949
/**
@@ -82,4 +82,14 @@ public function guess($path)
8282

8383
return $match[1];
8484
}
85+
86+
/**
87+
* @return bool
88+
*/
89+
private static function hasFileBinary()
90+
{
91+
static $exists;
92+
93+
return isset($exists) ? $exists : ($exists = null !== shell_exec('command -v file'));
94+
}
8595
}

0 commit comments

Comments
 (0)
0