Skip to content

Commit

Permalink
Merge pull request gallery#121 from shadlaws/fix_1935_only
Browse files Browse the repository at this point in the history
#1935 - Make FFmpeg easier to install.
  • Loading branch information
bharat committed Feb 11, 2013
2 parents 53ce9c8 + 1d7f5e3 commit 33149ef
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions modules/gallery/helpers/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 33149ef

Please sign in to comment.