Skip to content

Commit 8200522

Browse files
authored
Merge pull request nextcloud#49228 from nextcloud/backport/38630/stable29
[stable29] Fix remaining readdir() calls in loops with undesirable false evaluation potential
2 parents c869577 + 051af1a commit 8200522

File tree

8 files changed

+10
-10
lines changed

8 files changed

+10
-10
lines changed

apps/files_external/lib/Lib/Storage/Swift.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public function rmdir($path) {
261261
}
262262

263263
$dh = $this->opendir($path);
264-
while ($file = readdir($dh)) {
264+
while (($file = readdir($dh)) !== false) {
265265
if (\OC\Files\Filesystem::isIgnoredDir($file)) {
266266
continue;
267267
}
@@ -527,7 +527,7 @@ public function copy($source, $target) {
527527
}
528528

529529
$dh = $this->opendir($source);
530-
while ($file = readdir($dh)) {
530+
while (($file = readdir($dh)) !== false) {
531531
if (\OC\Files\Filesystem::isIgnoredDir($file)) {
532532
continue;
533533
}

apps/files_trashbin/lib/Trashbin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ private static function getTrashbinSize(string $user): int|float {
11411141
public static function isEmpty($user) {
11421142
$view = new View('/' . $user . '/files_trashbin');
11431143
if ($view->is_dir('/files') && $dh = $view->opendir('/files')) {
1144-
while ($file = readdir($dh)) {
1144+
while (($file = readdir($dh)) !== false) {
11451145
if (!Filesystem::isIgnoredDir($file)) {
11461146
return false;
11471147
}

lib/private/Files/Storage/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function copy($source, $target) {
232232
$this->remove($target);
233233
$dir = $this->opendir($source);
234234
$this->mkdir($target);
235-
while ($file = readdir($dir)) {
235+
while (($file = readdir($dir)) !== false) {
236236
if (!Filesystem::isIgnoredDir($file)) {
237237
if (!$this->copy($source . '/' . $file, $target . '/' . $file)) {
238238
closedir($dir);

lib/private/Files/Storage/PolyFill/CopyDirectory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function copy($source, $target) {
8686
protected function copyRecursive($source, $target) {
8787
$dh = $this->opendir($source);
8888
$result = true;
89-
while ($file = readdir($dh)) {
89+
while (($file = readdir($dh)) !== false) {
9090
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
9191
if ($this->is_dir($source . '/' . $file)) {
9292
$this->mkdir($target . '/' . $file);

tests/apps.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function loadDirectory($path): void {
1919
return;
2020
}
2121

22-
while ($name = readdir($dh)) {
22+
while (($name = readdir($dh)) !== false) {
2323
if ($name[0] === '.') {
2424
continue;
2525
}

tests/lib/Files/Storage/Storage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function testDirectories($directory) {
8181

8282
$dh = $this->instance->opendir('/');
8383
$content = [];
84-
while ($file = readdir($dh)) {
84+
while (($file = readdir($dh)) !== false) {
8585
if ($file != '.' and $file != '..') {
8686
$content[] = $file;
8787
}
@@ -114,7 +114,7 @@ public function testDirectories($directory) {
114114

115115
$dh = $this->instance->opendir('/');
116116
$content = [];
117-
while ($file = readdir($dh)) {
117+
while (($file = readdir($dh)) !== false) {
118118
if ($file != '.' and $file != '..') {
119119
$content[] = $file;
120120
}

tests/lib/Files/Storage/Wrapper/EncodingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function testNormalizedDirectoryEntriesOpenDir() {
209209

210210
$dh = $this->instance->opendir('/test');
211211
$content = [];
212-
while ($file = readdir($dh)) {
212+
while (($file = readdir($dh)) !== false) {
213213
if ($file != '.' and $file != '..') {
214214
$content[] = $file;
215215
}

tests/lib/Files/Storage/Wrapper/JailTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function tearDown(): void {
2828
// test that nothing outside our jail is touched
2929
$contents = [];
3030
$dh = $this->sourceStorage->opendir('');
31-
while ($file = readdir($dh)) {
31+
while (($file = readdir($dh)) !== false) {
3232
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
3333
$contents[] = $file;
3434
}

0 commit comments

Comments
 (0)