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

Bug: delete_files() and hidden directories #3015

Closed
MGatner opened this issue May 19, 2020 · 1 comment
Closed

Bug: delete_files() and hidden directories #3015

MGatner opened this issue May 19, 2020 · 1 comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@MGatner
Copy link
Member

MGatner commented May 19, 2020

Describe the bug
delete_files() in the Filesystem Helper currently ignores hidden directories. I'm not sure if this is a "bug" since the code seems to do it deliberately (notice the first line):

if (is_dir($path . DIRECTORY_SEPARATOR . $filename) && $filename[0] !== '.')
{
	delete_files($path . DIRECTORY_SEPARATOR . $filename, $del_dir, $htdocs, $_level + 1);
}
elseif ($htdocs !== true || ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename))
{
	@unlink($path . DIRECTORY_SEPARATOR . $filename);
}

But this isn't documented anywhere and seems an odd exclusion. For example, cleaning up an example project delete_files() fails to remove the root directory because it contains .github/.

If leaving hidden directories is intentional, then I would be in favor of giving this the same treatment as get_filenames(): remove the recursive call, use a RecursiveIteratorIterator instead, and add a parameter for bool $hidden = false.

CodeIgniter 4 version
develop

Affected module(s)
Helpers > Filesystem

Expected behavior, and steps to reproduce if appropriate
Given:
ROOT/app/[files]
ROOT/writable/[files]
ROOT/.github/[files]

I would expect calling delete_files('ROOT', true) to wipe the whole project, but it does not.

Context

  • OS: Linux
  • Web server: Apache
  • PHP version: 7.3
@MGatner MGatner added the bug Verified issues on the current code behavior or pull requests that will fix them label May 19, 2020
@lonnieezell
Copy link
Member

This is a direct port from previous versions, I believe, so I couldn't tell you the reasoning.

I'm good with your suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

2 participants