Skip to content

Commit

Permalink
Merge pull request #8298 from kenjis/fix-get-filenames-symlink
Browse files Browse the repository at this point in the history
fix: get_filenames() does not follow symlinks
  • Loading branch information
kenjis authored Dec 7, 2023
2 parents 29f7199 + 3b74ad0 commit b75a73f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
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

0 comments on commit b75a73f

Please sign in to comment.