Skip to content

Commit

Permalink
Don't assume that file binary exists on *nix OS
Browse files Browse the repository at this point in the history
Certain lightweight distributions such as Alpine Linux (popular for smaller Docker images) do not include it by default.
  • Loading branch information
teohhanhui committed Apr 12, 2018
1 parent 1067468 commit 825f359
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct($cmd = 'file -b --mime %s 2>/dev/null')
*/
public static function isSupported()
{
return '\\' !== DIRECTORY_SEPARATOR && function_exists('passthru') && function_exists('escapeshellarg');
return '\\' !== DIRECTORY_SEPARATOR && function_exists('passthru') && function_exists('escapeshellarg') && static::hasFileBinary();
}

/**
Expand Down Expand Up @@ -82,4 +82,14 @@ public function guess($path)

return $match[1];
}

/**
* @return bool
*/
private static function hasFileBinary()
{
static $result;

return isset($result) ? $result : ($result = null !== shell_exec('command -v file'));
}
}

0 comments on commit 825f359

Please sign in to comment.