diff options
author | Bharat Mediratta <bharat@menalto.com> | 2013-02-15 13:00:26 -0500 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2013-02-15 13:00:26 -0500 |
commit | 96a01c86d9bd15f9dc91c60be6f236deab2ffad9 (patch) | |
tree | db06b9a5ab2b03a0475f536b9792435059f999e9 /modules/gallery/helpers/system.php | |
parent | 16b8b8d16b8b46fe1e60b2a86f9ee5883dbc892f (diff) | |
parent | 5b6c138da1e53e93e4de8079885fcef29d12e673 (diff) |
Merge branch 'master' into jquery_190
Diffstat (limited to 'modules/gallery/helpers/system.php')
-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; |