From 1fc1543a8bcffa04f0c4d42ba2252409c8876041 Mon Sep 17 00:00:00 2001 From: Josh Richards Date: Sat, 3 Jun 2023 08:57:38 -0400 Subject: [PATCH 1/2] fix: 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/lib/Files/Storage/Storage.php | 4 ++-- tests/lib/Files/Storage/Wrapper/EncodingTest.php | 2 +- tests/lib/Files/Storage/Wrapper/JailTest.php | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/files_external/lib/Lib/Storage/Swift.php b/apps/files_external/lib/Lib/Storage/Swift.php index 1ae9659cd59bf..f25c3cb304be5 100644 --- a/apps/files_external/lib/Lib/Storage/Swift.php +++ b/apps/files_external/lib/Lib/Storage/Swift.php @@ -228,7 +228,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; } @@ -494,7 +494,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 a8ecc363e64c2..fe16a3a9d69c2 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -1105,7 +1105,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 5ffac31d68289..d4f3d1ddc847d 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -192,7 +192,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 4b3e367da78f7..5fe396d97e1d1 100644 --- a/lib/private/Files/Storage/PolyFill/CopyDirectory.php +++ b/lib/private/Files/Storage/PolyFill/CopyDirectory.php @@ -70,7 +70,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/lib/Files/Storage/Storage.php b/tests/lib/Files/Storage/Storage.php index 0a170a0e7d53b..747cb4b6f4392 100644 --- a/tests/lib/Files/Storage/Storage.php +++ b/tests/lib/Files/Storage/Storage.php @@ -66,7 +66,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; } @@ -99,7 +99,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 bc9355d7bfb19..ae6a6ece74261 100644 --- a/tests/lib/Files/Storage/Wrapper/EncodingTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncodingTest.php @@ -208,7 +208,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 c48f52ecce7ac..fb2d05d069171 100644 --- a/tests/lib/Files/Storage/Wrapper/JailTest.php +++ b/tests/lib/Files/Storage/Wrapper/JailTest.php @@ -27,7 +27,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; } From 3b336466e41182b6baa28989b3bc2086969ddc9e Mon Sep 17 00:00:00 2001 From: yemkareems Date: Wed, 13 Nov 2024 09:10:35 +0530 Subject: [PATCH 2/2] fix: conflicts resolved in apps.php loadDirectory Signed-off-by: yemkareems --- tests/apps.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/apps.php b/tests/apps.php index 1a9071aa2d3bf..d845cdf47c1db 100644 --- a/tests/apps.php +++ b/tests/apps.php @@ -14,7 +14,7 @@ function loadDirectory($path): void { return; } - while ($name = readdir($dh)) { + while (($name = readdir($dh)) !== false) { if ($name[0] === '.') { continue; }