From 80e0c9dcec88f4918d9554e7707674dca9f8ef88 Mon Sep 17 00:00:00 2001 From: Cole Thorsen <959538+colethorsen@users.noreply.github.com> Date: Thu, 16 Nov 2023 08:07:45 -0800 Subject: [PATCH 1/5] allow get_filenames to follow symlinks --- system/Helpers/filesystem_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 0e029b5986b66de50f19c88c7e4dfcc74c1fae76 Mon Sep 17 00:00:00 2001 From: Cole Thorsen <959538+colethorsen@users.noreply.github.com> Date: Thu, 16 Nov 2023 15:11:36 -0800 Subject: [PATCH 2/5] docs --- user_guide_src/source/changelogs/v4.4.4.rst | 6 ++++++ user_guide_src/source/helpers/filesystem_helper.rst | 2 ++ 2 files changed, 8 insertions(+) diff --git a/user_guide_src/source/changelogs/v4.4.4.rst b/user_guide_src/source/changelogs/v4.4.4.rst index 7ee96a53556f..582ee061e62c 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 +==================================== + +``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..8d7507304909 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. + Prior to v4.4.4, due to a bug, this function did not follow symlink folders. + Example: .. literalinclude:: filesystem_helper/010.php From 11b06caed6537a53b19a78ea09e3dbc10e00101a Mon Sep 17 00:00:00 2001 From: Cole Thorsen <959538+colethorsen@users.noreply.github.com> Date: Thu, 16 Nov 2023 15:28:22 -0800 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: kenjis --- user_guide_src/source/changelogs/v4.4.4.rst | 2 +- user_guide_src/source/helpers/filesystem_helper.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/changelogs/v4.4.4.rst b/user_guide_src/source/changelogs/v4.4.4.rst index 582ee061e62c..1f5c8450aefa 100644 --- a/user_guide_src/source/changelogs/v4.4.4.rst +++ b/user_guide_src/source/changelogs/v4.4.4.rst @@ -36,7 +36,7 @@ This was fixed and is now working according to documentation. You can define you Filesystem Helper ==================================== -``get_filenames()`` now follows symlink folders, which it previously just returned +:php:func:`get_filenames()` now follows symlink folders, which it previously just returned without following. *************** diff --git a/user_guide_src/source/helpers/filesystem_helper.rst b/user_guide_src/source/helpers/filesystem_helper.rst index 8d7507304909..0d0cc031caff 100644 --- a/user_guide_src/source/helpers/filesystem_helper.rst +++ b/user_guide_src/source/helpers/filesystem_helper.rst @@ -164,7 +164,7 @@ The following functions are available: the second parameter to 'relative' for relative paths or any other non-empty value for a full file path. - Prior to v4.4.4, due to a bug, this function did not follow symlink folders. + .. note:: Prior to v4.4.4, due to a bug, this function did not follow symlink folders. Example: From 681de6d336fe682313f86d3ca18407d78d5b9ae5 Mon Sep 17 00:00:00 2001 From: Cole Thorsen <959538+colethorsen@users.noreply.github.com> Date: Thu, 16 Nov 2023 15:57:50 -0800 Subject: [PATCH 4/5] Update user_guide_src/source/changelogs/v4.4.4.rst Co-authored-by: kenjis --- user_guide_src/source/changelogs/v4.4.4.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.4.4.rst b/user_guide_src/source/changelogs/v4.4.4.rst index 1f5c8450aefa..599681b48e4a 100644 --- a/user_guide_src/source/changelogs/v4.4.4.rst +++ b/user_guide_src/source/changelogs/v4.4.4.rst @@ -34,7 +34,7 @@ Due to a bug, we were using the undocumented `ssl_key` config option to define t 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. From 3b74ad02e4c56603992680e077d9bcc37212687c Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 6 Dec 2023 15:27:19 +0900 Subject: [PATCH 5/5] test: add test for get_filenames() --- tests/system/Helpers/FilesystemHelperTest.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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';