From e32968cfcea295f21336c1cda0bbe8d7a107b1eb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 19 Nov 2014 17:04:55 +0100 Subject: [PATCH 1/3] Remove exec() call with invalid name on windows Currently running unit tests prints the following message 3 times: The command "command" is misspelt or could not be found. Instead of trying this, we just skip this now. --- settings/admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/admin.php b/settings/admin.php index d1ed6e75f5..2b96461309 100644 --- a/settings/admin.php +++ b/settings/admin.php @@ -123,7 +123,7 @@ $template->printPage(); * @return null|string */ function findBinaryPath($program) { - if (OC_Helper::is_function_enabled('exec')) { + if (!\OC_Util::runningOnWindows() && \OC_Helper::is_function_enabled('exec')) { exec('command -v ' . escapeshellarg($program) . ' 2> /dev/null', $output, $returnCode); if ($returnCode === 0 && count($output) > 0) { return escapeshellcmd($output[0]); From 64421d76fdd8b718c3f0fccf94ba0028adc593b4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 20 Nov 2014 12:37:59 +0100 Subject: [PATCH 2/3] Deduplicate function by moving it to the OC_Helper --- lib/private/helper.php | 17 +++++++++++++++++ lib/private/preview/movies.php | 12 ++---------- settings/admin.php | 18 +----------------- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/lib/private/helper.php b/lib/private/helper.php index 5b1d31bfc5..be448b8ff9 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -872,6 +872,23 @@ class OC_Helper { return true; } + /** + * Try to find a program + * Note: currently windows is not supported + * + * @param string $program + * @return null|string + */ + public static function findBinaryPath($program) { + if (!\OC_Util::runningOnWindows() && self::is_function_enabled('exec')) { + exec('command -v ' . escapeshellarg($program) . ' 2> /dev/null', $output, $returnCode); + if ($returnCode === 0 && count($output) > 0) { + return escapeshellcmd($output[0]); + } + } + return null; + } + /** * Calculate the disc space for the given path * diff --git a/lib/private/preview/movies.php b/lib/private/preview/movies.php index 2a23c2141c..8217ad2440 100644 --- a/lib/private/preview/movies.php +++ b/lib/private/preview/movies.php @@ -8,14 +8,6 @@ */ namespace OC\Preview; -function findBinaryPath($program) { - exec('command -v ' . escapeshellarg($program) . ' 2> /dev/null', $output, $returnCode); - if ($returnCode === 0 && count($output) > 0) { - return escapeshellcmd($output[0]); - } - return null; -} - // movie preview is currently not supported on Windows if (!\OC_Util::runningOnWindows()) { $isExecEnabled = \OC_Helper::is_function_enabled('exec'); @@ -23,9 +15,9 @@ if (!\OC_Util::runningOnWindows()) { $avconvBinary = null; if ($isExecEnabled) { - $avconvBinary = findBinaryPath('avconv'); + $avconvBinary = \OC_Helper::findBinaryPath('avconv'); if (!$avconvBinary) { - $ffmpegBinary = findBinaryPath('ffmpeg'); + $ffmpegBinary = \OC_Helper::findBinaryPath('ffmpeg'); } } diff --git a/settings/admin.php b/settings/admin.php index 2b96461309..a669974891 100644 --- a/settings/admin.php +++ b/settings/admin.php @@ -17,7 +17,7 @@ $config = \OC::$server->getConfig(); $appConfig = \OC::$server->getAppConfig(); // Should we display sendmail as an option? -$template->assign('sendmail_is_available', (bool)findBinaryPath('sendmail')); +$template->assign('sendmail_is_available', (bool) \OC_Helper::findBinaryPath('sendmail')); $template->assign('loglevel', $config->getSystemValue("loglevel", 2)); $template->assign('mail_domain', $config->getSystemValue("mail_domain", '')); @@ -115,19 +115,3 @@ $formsAndMore[] = array('anchor' => 'log-section', 'section-name' => $l->t('Log' $template->assign('forms', $formsAndMore); $template->printPage(); - -/** - * Try to find a program - * - * @param string $program - * @return null|string - */ -function findBinaryPath($program) { - if (!\OC_Util::runningOnWindows() && \OC_Helper::is_function_enabled('exec')) { - exec('command -v ' . escapeshellarg($program) . ' 2> /dev/null', $output, $returnCode); - if ($returnCode === 0 && count($output) > 0) { - return escapeshellcmd($output[0]); - } - } - return null; -} From d15f1882f91c4ab71c8a41f62f5277bff5fa4ea6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 20 Nov 2014 12:41:55 +0100 Subject: [PATCH 3/3] Simplify the binary finding code in the movie preview class --- lib/private/preview/movies.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/private/preview/movies.php b/lib/private/preview/movies.php index 8217ad2440..d69266ceb3 100644 --- a/lib/private/preview/movies.php +++ b/lib/private/preview/movies.php @@ -10,18 +10,10 @@ namespace OC\Preview; // movie preview is currently not supported on Windows if (!\OC_Util::runningOnWindows()) { - $isExecEnabled = \OC_Helper::is_function_enabled('exec'); - $ffmpegBinary = null; - $avconvBinary = null; + $avconvBinary = \OC_Helper::findBinaryPath('avconv'); + $ffmpegBinary = ($avconvBinary) ? null : \OC_Helper::findBinaryPath('ffmpeg'); - if ($isExecEnabled) { - $avconvBinary = \OC_Helper::findBinaryPath('avconv'); - if (!$avconvBinary) { - $ffmpegBinary = \OC_Helper::findBinaryPath('ffmpeg'); - } - } - - if($isExecEnabled && ( $avconvBinary || $ffmpegBinary )) { + if ($avconvBinary || $ffmpegBinary) { class Movie extends Provider { public static $avconvBinary;