fix: handle null results in get_dir_file_info()#10407
Conversation
|
One question - do you not know how to perform On the topic of PR: after reading the directory, can there be a cache in the file system? Take a look at |
michalsn
left a comment
There was a problem hiding this comment.
Adding clearstatcache() would not solve the race because the file could disappear immediately afterward. More importantly, this fixes a deterministic bug: with $topLevelOnly = true, directories produce incomplete entries containing only relative_path.
We need a test, a changelog entry, and a small update to the PR description.
|
Those older commits were from accidentally staging files to the wrong branch, which led to me creating and then closing a few incorrect PRs. Sorry for the confusion — the current PR #10407 only contains the two relevant commits (fix + test). |
fb86f72 to
18bdafb
Compare
michalsn
left a comment
There was a problem hiding this comment.
Please add a changelog entry.
Co-authored-by: memleakd <121398829+memleakd@users.noreply.github.com>
| } elseif ($file[0] !== '.') { | ||
| $fileData[$file] = get_file_info($sourceDir . $file); | ||
| $fileData[$file]['relative_path'] = $relativePath; | ||
| if (($info = get_file_info($sourceDir . $file)) !== null) { |
There was a problem hiding this comment.
I'm not a fan of variable assignments within conditionals. Can you move it on its own line?
Description
Add null check in
get_dir_file_info()for whenget_file_info()returnsnull(race condition: file deleted afterreaddir()but beforeget_file_info()). This prevents broken entries and fixes random test failures inCommands. Includes unit test.Ref: #9968
Checklist: