Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get_filenames() does not follow symlinks #8298

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Helpers/filesystem_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions tests/system/Helpers/FilesystemHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 6 additions & 0 deletions user_guide_src/source/changelogs/v4.4.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
***************
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/helpers/filesystem_helper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading