Skip to content

Commit

Permalink
Merge branch 'm31_MDL-53837_Is_Executable_Python_Script_Windows' of h…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed May 9, 2016
2 parents 33b60a4 + bc21938 commit b0ab1fd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2543,9 +2543,10 @@ class admin_setting_configexecutable extends admin_setting_configfile {
public function output_html($data, $query='') {
global $CFG;
$default = $this->get_defaultsetting();
require_once("$CFG->libdir/filelib.php");

if ($data) {
if (file_exists($data) and !is_dir($data) and is_executable($data)) {
if (file_exists($data) and !is_dir($data) and file_is_executable($data)) {
$executable = '<span class="pathok">&#x2714;</span>';
} else {
$executable = '<span class="patherror">&#x2718;</span>';
Expand Down
29 changes: 29 additions & 0 deletions lib/filelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,35 @@ function file_modify_html_header($text) {
return $text;
}

/**
* Tells whether the filename is executable.
*
* @link http://php.net/manual/en/function.is-executable.php
* @link https://bugs.php.net/bug.php?id=41062
* @param string $filename Path to the file.
* @return bool True if the filename exists and is executable; otherwise, false.
*/
function file_is_executable($filename) {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
if (is_executable($filename)) {
return true;
} else {
$fileext = strrchr($filename, '.');
// If we have an extension we can check if it is listed as executable.
if ($fileext && file_exists($filename) && !is_dir($filename)) {
$winpathext = strtolower(getenv('PATHEXT'));
$winpathexts = explode(';', $winpathext);

return in_array(strtolower($fileext), $winpathexts);
}

return false;
}
} else {
return is_executable($filename);
}
}

/**
* RESTful cURL class
*
Expand Down
2 changes: 1 addition & 1 deletion lib/filestorage/file_storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected function is_format_supported_by_unoconv($format) {
protected function create_converted_document(stored_file $file, $format) {
global $CFG;

if (empty($CFG->pathtounoconv) || !is_executable(trim($CFG->pathtounoconv))) {
if (empty($CFG->pathtounoconv) || !file_is_executable(trim($CFG->pathtounoconv))) {
// No conversions are possible, sorry.
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/tests/unoconv_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function setUp() {
public function test_generate_pdf() {
global $CFG;

if (empty($CFG->pathtounoconv) || !is_executable(trim($CFG->pathtounoconv))) {
if (empty($CFG->pathtounoconv) || !file_is_executable(trim($CFG->pathtounoconv))) {
// No conversions are possible, sorry.
return $this->markTestSkipped();
}
Expand All @@ -90,7 +90,7 @@ public function test_generate_pdf() {
public function test_generate_markdown() {
global $CFG;

if (empty($CFG->pathtounoconv) || !is_executable(trim($CFG->pathtounoconv))) {
if (empty($CFG->pathtounoconv) || !file_is_executable(trim($CFG->pathtounoconv))) {
// No conversions are possible, sorry.
return $this->markTestSkipped();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ information provided here is intended especially for developers.
* table_sql download process is using the new data formats plugin which you can't use if you are buffering any output
* flexible_table::get_download_menu(), considered private, has been deleted. Use
$OUTPUT->download_dataformat_selector() instead.
when building Xpath, or pass the unescaped value when using the named selector.
* Add new file_is_executable(), to consistently check for executables even in Windows (PHP bug #41062).

=== 3.0 ===

Expand Down

0 comments on commit b0ab1fd

Please sign in to comment.