From e7cbaf3ee323c9187356300012c8cfb3879b0349 Mon Sep 17 00:00:00 2001 From: Josh Richards Date: Sat, 3 Jun 2023 08:57:38 -0400 Subject: [PATCH] Clean-up some remaining readdir calls with undesirable false evaluation potential Signed-off-by: Josh Richards --- apps/files_external/lib/Lib/Storage/Swift.php | 4 ++-- apps/files_trashbin/lib/Trashbin.php | 2 +- lib/private/Files/Storage/Common.php | 2 +- lib/private/Files/Storage/PolyFill/CopyDirectory.php | 2 +- tests/apps.php | 2 +- tests/lib/Files/Storage/Storage.php | 4 ++-- tests/lib/Files/Storage/Wrapper/EncodingTest.php | 2 +- tests/lib/Files/Storage/Wrapper/JailTest.php | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/files_external/lib/Lib/Storage/Swift.php b/apps/files_external/lib/Lib/Storage/Swift.php index 26e6c5315cbf4..aaa707b43e85d 100644 --- a/apps/files_external/lib/Lib/Storage/Swift.php +++ b/apps/files_external/lib/Lib/Storage/Swift.php @@ -261,7 +261,7 @@ public function rmdir($path) { } $dh = $this->opendir($path); - while ($file = readdir($dh)) { + while (($file = readdir($dh)) !== false) { if (\OC\Files\Filesystem::isIgnoredDir($file)) { continue; } @@ -527,7 +527,7 @@ public function copy($source, $target) { } $dh = $this->opendir($source); - while ($file = readdir($dh)) { + while (($file = readdir($dh)) !== false) { if (\OC\Files\Filesystem::isIgnoredDir($file)) { continue; } diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index 90f74e51e8167..9ba535e376eae 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -1114,7 +1114,7 @@ private static function getTrashbinSize(string $user): int|float { public static function isEmpty($user) { $view = new View('/' . $user . '/files_trashbin'); if ($view->is_dir('/files') && $dh = $view->opendir('/files')) { - while ($file = readdir($dh)) { + while (($file = readdir($dh)) !== false) { if (!Filesystem::isIgnoredDir($file)) { return false; } diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 5ab411434d0b5..15fe788a82112 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -228,7 +228,7 @@ public function copy($source, $target) { $this->remove($target); $dir = $this->opendir($source); $this->mkdir($target); - while ($file = readdir($dir)) { + while (($file = readdir($dir)) !== false) { if (!Filesystem::isIgnoredDir($file)) { if (!$this->copy($source . '/' . $file, $target . '/' . $file)) { closedir($dir); diff --git a/lib/private/Files/Storage/PolyFill/CopyDirectory.php b/lib/private/Files/Storage/PolyFill/CopyDirectory.php index ff05eecb134ce..c22b9edc592d1 100644 --- a/lib/private/Files/Storage/PolyFill/CopyDirectory.php +++ b/lib/private/Files/Storage/PolyFill/CopyDirectory.php @@ -86,7 +86,7 @@ public function copy($source, $target) { protected function copyRecursive($source, $target) { $dh = $this->opendir($source); $result = true; - while ($file = readdir($dh)) { + while (($file = readdir($dh)) !== false) { if (!\OC\Files\Filesystem::isIgnoredDir($file)) { if ($this->is_dir($source . '/' . $file)) { $this->mkdir($target . '/' . $file); diff --git a/tests/apps.php b/tests/apps.php index 27bd428d949ef..f97aff8c4b707 100644 --- a/tests/apps.php +++ b/tests/apps.php @@ -14,7 +14,7 @@ function loadDirectory($path) { return; } if ($dh = opendir($path)) { - while ($name = readdir($dh)) { + while (($name = readdir($dh)) !== false) { if ($name[0] !== '.') { $file = $path . '/' . $name; if (is_dir($file)) { diff --git a/tests/lib/Files/Storage/Storage.php b/tests/lib/Files/Storage/Storage.php index a646fd5fd0ba4..6c86c58a27210 100644 --- a/tests/lib/Files/Storage/Storage.php +++ b/tests/lib/Files/Storage/Storage.php @@ -81,7 +81,7 @@ public function testDirectories($directory) { $dh = $this->instance->opendir('/'); $content = []; - while ($file = readdir($dh)) { + while (($file = readdir($dh)) !== false) { if ($file != '.' and $file != '..') { $content[] = $file; } @@ -113,7 +113,7 @@ public function testDirectories($directory) { $dh = $this->instance->opendir('/'); $content = []; - while ($file = readdir($dh)) { + while (($file = readdir($dh)) !== false) { if ($file != '.' and $file != '..') { $content[] = $file; } diff --git a/tests/lib/Files/Storage/Wrapper/EncodingTest.php b/tests/lib/Files/Storage/Wrapper/EncodingTest.php index 0901edf83fa06..3f14ec6499516 100644 --- a/tests/lib/Files/Storage/Wrapper/EncodingTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncodingTest.php @@ -209,7 +209,7 @@ public function testNormalizedDirectoryEntriesOpenDir() { $dh = $this->instance->opendir('/test'); $content = []; - while ($file = readdir($dh)) { + while (($file = readdir($dh)) !== false) { if ($file != '.' and $file != '..') { $content[] = $file; } diff --git a/tests/lib/Files/Storage/Wrapper/JailTest.php b/tests/lib/Files/Storage/Wrapper/JailTest.php index 148bd3a4f30c2..01fd67ddfb869 100644 --- a/tests/lib/Files/Storage/Wrapper/JailTest.php +++ b/tests/lib/Files/Storage/Wrapper/JailTest.php @@ -28,7 +28,7 @@ protected function tearDown(): void { // test that nothing outside our jail is touched $contents = []; $dh = $this->sourceStorage->opendir(''); - while ($file = readdir($dh)) { + while (($file = readdir($dh)) !== false) { if (!\OC\Files\Filesystem::isIgnoredDir($file)) { $contents[] = $file; }