diff options
author | shadlaws <shad@shadlaws.com> | 2013-02-09 20:48:02 +0100 |
---|---|---|
committer | shadlaws <shad@shadlaws.com> | 2013-02-09 20:48:02 +0100 |
commit | 1d7f5e3ab117a6cce8f2a1d3de5e311b74dbee81 (patch) | |
tree | cabf38aa084c01a92ed89020e3ec1ad2e0eabb39 /modules/gallery | |
parent | a06faf61b40b458870bad5e66e2666c90032ee2d (diff) |
#1935 - Make FFmpeg easier to install.
- system::find_binary - add Gallery's bin subdirectory to search
- system::find_binary - auto-fix permissions if found in Gallery's bin directory
Diffstat (limited to 'modules/gallery')
-rw-r--r-- | modules/gallery/helpers/system.php | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php index fa834824..e1398103 100644 --- a/modules/gallery/helpers/system.php +++ b/modules/gallery/helpers/system.php @@ -20,22 +20,42 @@ class system_Core { /** * Return the path to an executable version of the named binary, or null. - * Traverse the PATH environment variable looking for the given file. If - * the $priority_path variable is set, check that path first. + * The paths are traversed in the following order: + * 1. $priority_path (if specified) + * 2. Gallery's own bin directory (DOCROOT . "bin") + * 3. PATH environment variable + * 4. extra_binary_paths Gallery variable (if specified) + * In addition, if the file is found inside Gallery's bin directory but + * it's not executable, we try to change its permissions to 0755. + * + * @param string $binary + * @param string $priority_path (optional) + * @return string path to binary if found; null if not found */ static function find_binary($binary, $priority_path=null) { - $paths = array_merge( - explode(":", getenv("PATH")), - explode(":", module::get_var("gallery", "extra_binary_paths"))); + $bin_path = DOCROOT . "bin"; + if ($priority_path) { - array_unshift($paths, $priority_path); + $paths = array($priority_path, $bin_path); + } else { + $paths = array($bin_path); } + $paths = array_merge($paths, + explode(":", getenv("PATH")), + explode(":", module::get_var("gallery", "extra_binary_paths"))); foreach ($paths as $path) { $candidate = "$path/$binary"; // @suppress errors below to avoid open_basedir issues - if (@file_exists($candidate) && @is_executable($candidate)) { - return $candidate; + if (@file_exists($candidate)) { + if (!@is_executable($candidate) && + (substr_compare($bin_path, $candidate, 0, strlen($bin_path)) == 0)) { + // Binary isn't executable but is in Gallery's bin directory - try fixing permissions. + @chmod($candidate, 0755); + } + if (@is_executable($candidate)) { + return $candidate; + } } } return null; |