MDL-70990 core: Ignore amd directory in plugin-like lists

The `get_list_of_plugins()` function is used to fetch plugin-like files
or directories from a specified directory. A number of standard
exclusions are included but this list is not the same as the list in
`core_component`.

The list has been updated to include the `amd` directory, which is
regularly used in both components, and plugins.
This commit is contained in:
Andrew Nicols 2021-03-01 20:25:39 +08:00
parent efb3d4e7a7
commit 053b0462fd
2 changed files with 112 additions and 3 deletions

View File

@ -7847,15 +7847,30 @@ function get_list_of_plugins($directory='mod', $exclude='', $basedir='') {
unset($subtypes);
}
$ignorelist = array_flip(array_filter([
'CVS',
'_vti_cnf',
'amd',
'classes',
'simpletest',
'tests',
'yui',
$exclude,
]));
if (file_exists($basedir) && filetype($basedir) == 'dir') {
if (!$dirhandle = opendir($basedir)) {
debugging("Directory permission error for plugin ({$directory}). Directory exists but cannot be read.", DEBUG_DEVELOPER);
return array();
}
while (false !== ($dir = readdir($dirhandle))) {
// Func: strpos is marginally but reliably faster than substr($dir, 0, 1).
if (strpos($dir, '.') === 0 or $dir === 'CVS' or $dir === '_vti_cnf' or $dir === 'simpletest' or $dir === 'yui' or
$dir === 'tests' or $dir === 'classes' or $dir === $exclude) {
if (strpos($dir, '.') === 0) {
// Ignore directories starting with .
// These are treated as hidden directories.
continue;
}
if (array_key_exists($dir, $ignorelist)) {
// This directory features on the ignore list.
continue;
}
if (filetype($basedir .'/'. $dir) != 'dir') {

View File

@ -5019,4 +5019,98 @@ EOF;
$result = display_size($size);
$this->assertEquals($expected, $result);
}
/**
* Test that the get_list_of_plugins function includes/excludes directories as appropriate.
*
* @dataProvider get_list_of_plugins_provider
* @param array $expectedlist The expected list of folders
* @param array $content The list of file content to set up in the virtual file root
* @param string $dir The base dir to look at in the virtual file root
* @param string $exclude Any additional folder to exclude
*/
public function test_get_list_of_plugins(array $expectedlist, array $content, string $dir, string $exclude): void {
$vfileroot = \org\bovigo\vfs\vfsStream::setup('root', null, $content);
$base = \org\bovigo\vfs\vfsStream::url('root');
$this->assertEquals($expectedlist, get_list_of_plugins($dir, $exclude, $base));
}
/**
* Data provider for get_list_of_plugins checks.
*
* @return array
*/
public function get_list_of_plugins_provider(): array {
return [
'Standard excludes' => [
['amdd', 'class', 'local', 'test'],
[
'.' => [],
'..' => [],
'amd' => [],
'amdd' => [],
'class' => [],
'classes' => [],
'local' => [],
'test' => [],
'tests' => [],
'yui' => [],
],
'',
'',
],
'Standard excludes with addition' => [
['amdd', 'local', 'test'],
[
'.' => [],
'..' => [],
'amd' => [],
'amdd' => [],
'class' => [],
'classes' => [],
'local' => [],
'test' => [],
'tests' => [],
'yui' => [],
],
'',
'class',
],
'Files excluded' => [
['def'],
[
'.' => [],
'..' => [],
'abc' => 'File with filename abc',
'def' => [
'.' => [],
'..' => [],
'example.txt' => 'In a directory called "def"',
],
],
'',
'',
],
'Subdirectories only' => [
['abc'],
[
'.' => [],
'..' => [],
'foo' => [
'.' => [],
'..' => [],
'abc' => [],
],
'bar' => [
'.' => [],
'..' => [],
'def' => [],
],
],
'foo',
'',
],
];
}
}