server icon indicating copy to clipboard operation
server copied to clipboard

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

Open joshtrichards opened this issue 2 years ago • 2 comments

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

joshtrichards avatar Jun 03 '23 14:06 joshtrichards

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);
}

🤔

solracsf avatar Jun 03 '23 14:06 solracsf

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

joshtrichards avatar Jun 16 '23 15:06 joshtrichards

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

blizzz avatar Jul 10 '23 10:07 blizzz