-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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: allow get_filenames() to follow symlinks #8225
fix: allow get_filenames() to follow symlinks #8225
Conversation
There is no description for symlinks in the user guides. In CI3: $ ls -l
total 16
-rw-r--r-- 1 kenji staff 706 Nov 17 06:27 Welcome.php
-rw-r--r-- 1 kenji staff 141 Mar 17 2023 index.html
lrwxr-xr-x 1 kenji staff 8 Nov 17 06:29 views -> ../views public function index()
{
$this->load->helper('file');
var_dump(get_filenames(__DIR__));
}
|
In CI4 $ ls -l
total 16
-rw-r--r-- 1 kenji staff 1579 Oct 27 16:48 BaseController.php
-rw-r--r-- 1 kenji staff 161 Nov 16 10:10 Home.php
lrwxr-xr-x 1 kenji staff 8 Nov 17 06:31 Views -> ../Views public function index()
{
helper('filesystem');
dd(get_filenames(APPPATH . 'Controllers/'));
}
|
@colethorsen Thank you. This is a bug. Symlink folders also should be followed. But this changes the behavior, so can you add a short description for it in the changelog? Also we expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works. Can you add test code? |
It appears that vfsStream does not support testing symlinks bovigo/vfsStream#89 if you have any thoughts on how this should be tested alternatively let me know. |
Co-authored-by: kenjis <[email protected]>
--- a/tests/system/Helpers/FilesystemHelperTest.php
+++ b/tests/system/Helpers/FilesystemHelperTest.php
@@ -396,6 +396,31 @@ final class FilesystemHelperTest extends CIUnitTestCase
$this->assertSame([], get_filenames(SUPPORTPATH . 'Files/shaker/'));
}
+ public function testGetFilenamesWithSymlinks(): void
+ {
+ $targetDir = APPPATH . 'Language';
+ $linkDir = APPPATH . 'Controllers/Language';
+ unlink($linkDir);
+ symlink($targetDir, $linkDir);
+
+ $targetFile = APPPATH . 'Common.php';
+ $linkFile = APPPATH . 'Controllers/Common.php';
+ 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'; |
Co-authored-by: kenjis <[email protected]>
Can you add a test? |
👋 Hi, @colethorsen! |
Closed by #8298 |
Description
While symlinks that are going directly to a file are followed, the
RecursiveDirectoryIterator
does not follow folder based symlinks without setting the proper flag.to
Originally posted by @colethorsen in #8216 (comment)
Checklist: