Skip to content

Commit b75a73f

Browse files
authored
Merge pull request #8298 from kenjis/fix-get-filenames-symlink
fix: get_filenames() does not follow symlinks
2 parents 29f7199 + 3b74ad0 commit b75a73f

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

system/Helpers/filesystem_helper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function get_filenames(
209209

210210
try {
211211
foreach (new RecursiveIteratorIterator(
212-
new RecursiveDirectoryIterator($sourceDir, RecursiveDirectoryIterator::SKIP_DOTS),
212+
new RecursiveDirectoryIterator($sourceDir, RecursiveDirectoryIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS),
213213
RecursiveIteratorIterator::SELF_FIRST
214214
) as $name => $object) {
215215
$basename = pathinfo($name, PATHINFO_BASENAME);

tests/system/Helpers/FilesystemHelperTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,35 @@ public function testGetFilenamesFailure(): void
396396
$this->assertSame([], get_filenames(SUPPORTPATH . 'Files/shaker/'));
397397
}
398398

399+
public function testGetFilenamesWithSymlinks(): void
400+
{
401+
$targetDir = APPPATH . 'Language';
402+
$linkDir = APPPATH . 'Controllers/Language';
403+
if (file_exists($linkDir)) {
404+
unlink($linkDir);
405+
}
406+
symlink($targetDir, $linkDir);
407+
408+
$targetFile = APPPATH . 'Common.php';
409+
$linkFile = APPPATH . 'Controllers/Common.php';
410+
if (file_exists($linkFile)) {
411+
unlink($linkFile);
412+
}
413+
symlink($targetFile, $linkFile);
414+
415+
$this->assertSame([
416+
0 => 'BaseController.php',
417+
1 => 'Common.php',
418+
2 => 'Home.php',
419+
3 => 'Language',
420+
4 => 'Validation.php',
421+
5 => 'en',
422+
], get_filenames(APPPATH . 'Controllers'));
423+
424+
unlink($linkDir);
425+
unlink($linkFile);
426+
}
427+
399428
public function testGetDirFileInfo(): void
400429
{
401430
$file = SUPPORTPATH . 'Files/baker/banana.php';

user_guide_src/source/changelogs/v4.4.4.rst

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ The use of the `ssl_key` option in CURLRequest was removed
3333
Due to a bug, we were using the undocumented `ssl_key` config option to define the CA bundle in CURLRequest.
3434
This was fixed and is now working according to documentation. You can define your CA bundle via the `verify` option.
3535

36+
Filesystem Helper
37+
=================
38+
39+
:php:func:`get_filenames()` now follows symlink folders, which it previously just returned
40+
without following.
41+
3642
***************
3743
Message Changes
3844
***************

user_guide_src/source/helpers/filesystem_helper.rst

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ The following functions are available:
164164
the second parameter to 'relative' for relative paths or any other non-empty value for
165165
a full file path.
166166

167+
.. note:: Prior to v4.4.4, due to a bug, this function did not follow symlink folders.
168+
167169
Example:
168170

169171
.. literalinclude:: filesystem_helper/010.php

0 commit comments

Comments
 (0)