From 23eaec7063b81d4dae04ec3f5c311a0a2f228a05 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 10 Jan 2011 15:49:15 -0800 Subject: Stop using "which" to find binaries. Create system::find_binary() which traverses the $PATH and returns any executable binary of the appropriate name that it can find. Fixes #1555. --- modules/gallery/helpers/graphics.php | 8 ++----- modules/gallery/helpers/movie.php | 14 +++++------- modules/gallery/helpers/system.php | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 modules/gallery/helpers/system.php (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 29527705..18820ed7 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -313,11 +313,6 @@ class graphics_Core { $toolkits->graphicsmagick->installed = false; $toolkits->graphicsmagick->error = t("GraphicsMagick requires the exec function"); } else { - gallery::set_path_env( - array(module::get_var("gallery", "graphics_toolkit_path"), - getenv("PATH"), - module::get_var("gallery", "extra_binary_paths"))); - // ImageMagick & GraphicsMagick $magick_kits = array( "imagemagick" => array( @@ -328,7 +323,8 @@ class graphics_Core { "version_regex" => "/\S+ (\S+)/")); // Loop through the kits foreach ($magick_kits as $index => $settings) { - $path = exec("which " . $settings["binary"]); + $path = system::find_binary( + $settings["binary"], module::get_var("gallery", "graphics_toolkit_path")); $toolkits->$index->name = $settings["name"]; if ($path) { if (@is_file($path) && diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 0895c5f4..dd0b437e 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -83,22 +83,18 @@ class movie_Core { } } + /** + * Return the path to the ffmpeg binary if one exists and is executable, or null. + */ static function find_ffmpeg() { if (!($ffmpeg_path = module::get_var("gallery", "ffmpeg_path")) || !file_exists($ffmpeg_path)) { - gallery::set_path_env( - array(module::get_var("gallery", "graphics_toolkit_path"), - getenv("PATH"), - module::get_var("gallery", "extra_binary_paths"))); - if (function_exists("exec")) { - $ffmpeg_path = exec("which ffmpeg"); - } - + $ffmpeg_path = system::find_binary( + "ffmpeg", module::get_var("gallery", "graphics_toolkit_path")); module::set_var("gallery", "ffmpeg_path", $ffmpeg_path); } return $ffmpeg_path; } - /** * Return the width, height, mime_type and extension of the given movie file. */ diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php new file mode 100644 index 00000000..4a6a3c0f --- /dev/null +++ b/modules/gallery/helpers/system.php @@ -0,0 +1,43 @@ +