[wp-trac] [WordPress Trac] #65150: Issue with copy_dir() function t does not skips folders.
WordPress Trac
noreply at wordpress.org
Thu Apr 30 04:48:09 UTC 2026
#65150: Issue with copy_dir() function t does not skips folders.
----------------------------+------------------------------
Reporter: neo2k23 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Filesystem API | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
----------------------------+------------------------------
Comment (by hbhalodia):
Hi @neo2k23, Thanks for pointing it out.
{{{
str_contains( $skip_item, '/' )
}}}
It is not the actual place where the `copy_dir` function checks to skip
the file/folder or whether to include it.
The current update which I have shared only determines, whether the item
which we need to skip is a `bare-name` (without '/' eg: 'abcd') or a
`path-based-item` (with '/' eg: 'xyz/abcd.txt', so that we know whether to
propogate it downward or not. As you see in next line we have a recursion,
that again calls `copy_dir` with new parameters to check.
The case you are saying for file check all happens here, line `2033` as
shown below.
{{{
if ( in_array( $filename, $skip_list, true ) ) {
continue;
}
}}}
Also the above line is a strict match comparision, that is,
{{{
in_array( 'skip-me', array('skip-me'), true ) → true → skipped ✅
in_array( 'abcd-skip-me', array('skip-me'), true ) → false → NOT skipped
✅
in_array( 'skip-me-abcd', array('skip-me'), true ) → false → NOT skipped
✅
}}}
The line added is only for the propogation, to pass the `file` down to
child diretories unchanged.
So a folder, `folderB/folderC/abcd-skip-me/ would never be skipped because
'abcd-skip-me' !== 'skip-me'`.
Also you can test the PR attached with multiple edge cases and let me know
if there is anything is failing. I would be happy to fix that.
Thanks,
--
Ticket URL: <https://core.trac.wordpress.org/ticket/65150#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list