diff --git a/system/Helpers/filesystem_helper.php b/system/Helpers/filesystem_helper.php index 47c829bbc3c6..4e0e8b1532e9 100644 --- a/system/Helpers/filesystem_helper.php +++ b/system/Helpers/filesystem_helper.php @@ -209,7 +209,7 @@ function get_filenames( try { foreach (new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($sourceDir, RecursiveDirectoryIterator::SKIP_DOTS), + new RecursiveDirectoryIterator($sourceDir, RecursiveDirectoryIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS), RecursiveIteratorIterator::SELF_FIRST ) as $name => $object) { $basename = pathinfo($name, PATHINFO_BASENAME); diff --git a/tests/system/Helpers/FilesystemHelperTest.php b/tests/system/Helpers/FilesystemHelperTest.php index e92505cc8a91..987e11eb5dcb 100644 --- a/tests/system/Helpers/FilesystemHelperTest.php +++ b/tests/system/Helpers/FilesystemHelperTest.php @@ -396,6 +396,35 @@ public function testGetFilenamesFailure(): void $this->assertSame([], get_filenames(SUPPORTPATH . 'Files/shaker/')); } + public function testGetFilenamesWithSymlinks(): void + { + $targetDir = APPPATH . 'Language'; + $linkDir = APPPATH . 'Controllers/Language'; + if (file_exists($linkDir)) { + unlink($linkDir); + } + symlink($targetDir, $linkDir); + + $targetFile = APPPATH . 'Common.php'; + $linkFile = APPPATH . 'Controllers/Common.php'; + if (file_exists($linkFile)) { + unlink($linkFile); + } + symlink($targetFile, $linkFile); + + $this->assertSame([ + 0 => 'BaseController.php', + 1 => 'Common.php', + 2 => 'Home.php', + 3 => 'Language', + 4 => 'Validation.php', + 5 => 'en', + ], get_filenames(APPPATH . 'Controllers')); + + unlink($linkDir); + unlink($linkFile); + } + public function testGetDirFileInfo(): void { $file = SUPPORTPATH . 'Files/baker/banana.php'; diff --git a/user_guide_src/source/changelogs/v4.4.4.rst b/user_guide_src/source/changelogs/v4.4.4.rst index 7ee96a53556f..599681b48e4a 100644 --- a/user_guide_src/source/changelogs/v4.4.4.rst +++ b/user_guide_src/source/changelogs/v4.4.4.rst @@ -33,6 +33,12 @@ The use of the `ssl_key` option in CURLRequest was removed Due to a bug, we were using the undocumented `ssl_key` config option to define the CA bundle in CURLRequest. This was fixed and is now working according to documentation. You can define your CA bundle via the `verify` option. +Filesystem Helper +================= + +:php:func:`get_filenames()` now follows symlink folders, which it previously just returned +without following. + *************** Message Changes *************** diff --git a/user_guide_src/source/helpers/filesystem_helper.rst b/user_guide_src/source/helpers/filesystem_helper.rst index e122660959c5..0d0cc031caff 100644 --- a/user_guide_src/source/helpers/filesystem_helper.rst +++ b/user_guide_src/source/helpers/filesystem_helper.rst @@ -164,6 +164,8 @@ The following functions are available: the second parameter to 'relative' for relative paths or any other non-empty value for a full file path. + .. note:: Prior to v4.4.4, due to a bug, this function did not follow symlink folders. + Example: .. literalinclude:: filesystem_helper/010.php