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

Fix remaining readdir() calls in loops with undesirable false evaluation potential #38630

Merged
merged 2 commits into from
Aug 16, 2024

Conversation

joshtrichards
Copy link
Member

@joshtrichards joshtrichards commented Jun 3, 2023

Summary

Fixes all remaining readdir() calls within loops that had undesirable false evaluation potential (at least in server)

There weren't too many left and the bulk were in tests. The most notable not in tests were these:

  • copy() in \OC\Files\Storage\Common
  • isEmpty() in OCA\Files_Trashbin\Trashbin
  • copyRecursive() in OC\Files\Storage\PolyFill\CopyDirectory

Ref: https://www.php.net/manual/en/function.readdir.php

TODO

  • ...

Checklist

Copy link
Member

@solracsf solracsf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, avoid "falsy" and ensure "false". 🆗

@solracsf solracsf added the 3. to review Waiting for reviews label Jun 3, 2023
@solracsf solracsf added this to the Nextcloud 28 milestone Jun 3, 2023
@@ -260,7 +260,7 @@
}

$dh = $this->opendir($path);
while ($file = readdir($dh)) {
while (($file = readdir($dh)) !== false) {

Check notice

Code scanning / Psalm

PossiblyFalseArgument Note

Argument 1 of readdir cannot be false, possibly resource value expected
@@ -526,7 +526,7 @@
}

$dh = $this->opendir($source);
while ($file = readdir($dh)) {
while (($file = readdir($dh)) !== false) {

Check notice

Code scanning / Psalm

PossiblyFalseArgument Note

Argument 1 of readdir cannot be false, possibly resource value expected
@solracsf
Copy link
Member

solracsf commented Jun 3, 2023

I wonder if these Psaml warnings worth something like:

// Open the directory and obtain a resource handle
$dh = opendir($directory);

// Check if the directory was opened successfully
if (is_resource($dh)) {
    // Iterate through directory entries
    while (($file = readdir($dh)) !== false) {
        // Process each file or directory
    }

    // Close the directory handle
    closedir($dh);
}

🤔

@joshtrichards
Copy link
Member Author

I don't think any of these test fails are related to this PR. 😕

…on potential

Signed-off-by: Josh Richards <josh.t.richards@gmail.com>
@blizzz
Copy link
Member

blizzz commented Jul 10, 2023

The psalm warnings are likely not new, but silenced before. opendir may return false, which is not what readdir likes.

@skjnldsv skjnldsv mentioned this pull request Nov 1, 2023
This was referenced Nov 6, 2023
This was referenced Nov 14, 2023
@blizzz blizzz modified the milestones: Nextcloud 28, Nextcloud 29 Nov 23, 2023
This was referenced Mar 12, 2024
This was referenced Mar 20, 2024
@skjnldsv skjnldsv mentioned this pull request Mar 28, 2024
81 tasks
@skjnldsv skjnldsv removed this from the Nextcloud 29 milestone Mar 28, 2024
@skjnldsv skjnldsv added this to the Nextcloud 30 milestone Mar 28, 2024
@skjnldsv skjnldsv added 2. developing Work in progress stale Ticket or PR with no recent activity and removed 3. to review Waiting for reviews labels Jul 27, 2024
This was referenced Jul 30, 2024
This was referenced Aug 5, 2024
@skjnldsv skjnldsv mentioned this pull request Aug 13, 2024
@skjnldsv skjnldsv closed this Aug 14, 2024
@skjnldsv skjnldsv removed this from the Nextcloud 30 milestone Aug 14, 2024
@skjnldsv skjnldsv reopened this Aug 16, 2024
Signed-off-by: John Molakvoæ <skjnldsv@users.noreply.github.com>
@skjnldsv
Copy link
Member

Rebased! Let's hope it works this time !! 💪

@skjnldsv skjnldsv added 4. to release Ready to be released and/or waiting for tests to finish technical debt and removed 2. developing Work in progress stale Ticket or PR with no recent activity labels Aug 16, 2024
@skjnldsv skjnldsv self-assigned this Aug 16, 2024
@skjnldsv
Copy link
Member

🎉 🎉 🎉

@skjnldsv skjnldsv merged commit d94073d into nextcloud:master Aug 16, 2024
157 of 163 checks passed
@skjnldsv skjnldsv added this to the Nextcloud 31 milestone Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants