Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitad148d7

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 parent1067468 commitad148d7

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

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

Lines changed: 31 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
publicstaticfunctionisSupported()
4545
{
46-
return'\\' !==DIRECTORY_SEPARATOR &&function_exists('passthru') &&function_exists('escapeshellarg');
46+
return'\\' !==DIRECTORY_SEPARATOR &&function_exists('passthru') &&function_exists('escapeshellarg') &&self::hasFileBinary();
4747
}
4848

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

8383
return$match[1];
8484
}
85+
86+
/**
87+
* @return bool
88+
*/
89+
privatestaticfunctionhasFileBinary()
90+
{
91+
static$exists;
92+
93+
if (isset($exists)) {
94+
return$exists;
95+
}
96+
97+
ob_start();
98+
99+
passthru('command -v file',$return);
100+
if ($return >0) {
101+
ob_end_clean();
102+
103+
return$exists =false;
104+
}
105+
106+
$binPath =trim(ob_get_clean());
107+
108+
if (!preg_match('#^(?:/[^\0/])+#',$binPath)) {
109+
// it's not a bin path, but an error message
110+
return$exists =false;
111+
}
112+
113+
return$exists =true;
114+
}
85115
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp