diff --git a/apps/encryption/lib/Command/FixKeyLocation.php b/apps/encryption/lib/Command/FixKeyLocation.php index b961b40f57297..e386dd714f4a8 100644 --- a/apps/encryption/lib/Command/FixKeyLocation.php +++ b/apps/encryption/lib/Command/FixKeyLocation.php @@ -366,6 +366,7 @@ private function findKeysByFileName(string $basePath, string $name) { } } } + closedir($dh); } } diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index 90f74e51e8167..81560781f6ca8 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -1119,6 +1119,7 @@ public static function isEmpty($user) { return false; } } + closedir($dh); } return true; } diff --git a/lib/private/Archive/Archive.php b/lib/private/Archive/Archive.php index ff6456113f832..2204c8ccb18cc 100644 --- a/lib/private/Archive/Archive.php +++ b/lib/private/Archive/Archive.php @@ -120,6 +120,7 @@ public function addRecursive(string $path, string $source): void { $this->addFile($path.'/'.$file, $source.'/'.$file); } } + closedir($dh); } } } diff --git a/lib/private/Cache/File.php b/lib/private/Cache/File.php index 72fc95a802b19..c0ea7a265a10e 100644 --- a/lib/private/Cache/File.php +++ b/lib/private/Cache/File.php @@ -156,14 +156,15 @@ public function remove($key) { */ public function clear($prefix = '') { $storage = $this->getStorage(); - if ($storage and $storage->is_dir('/')) { + if ($storage && $storage->is_dir('/')) { $dh = $storage->opendir('/'); if (is_resource($dh)) { while (($file = readdir($dh)) !== false) { - if ($file != '.' and $file != '..' and ($prefix === '' || str_starts_with($file, $prefix))) { + if ($file != '.' && $file != '..' && ($prefix === '' || str_starts_with($file, $prefix))) { $storage->unlink('/' . $file); } } + closedir($dh); } } return true; @@ -184,7 +185,7 @@ public function gc() { return null; } while (($file = readdir($dh)) !== false) { - if ($file != '.' and $file != '..') { + if ($file != '.' && $file != '..') { try { $mtime = $storage->filemtime('/' . $file); if ($mtime < $now) { @@ -200,6 +201,7 @@ public function gc() { } } } + closedir($dh); } } diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 3d5a2f098b2ac..2bdfb8efbe25f 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -294,6 +294,7 @@ private function addLocalFolder($path, $target) { } } } + closedir($dh); } } @@ -317,8 +318,8 @@ protected function searchInDir($query, $dir = '') { $files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item)); } } + closedir($dh); } - closedir($dh); return $files; } @@ -626,6 +627,7 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t $result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file); } } + closedir($dh); } } else { $source = $sourceStorage->fopen($sourceInternalPath, 'r'); @@ -905,6 +907,7 @@ public function getDirectoryContent($directory): \Traversable { } } } + closedir($dh); } } } diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 7ce4338256f01..1ef8e045267f1 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -824,11 +824,12 @@ private function copyBetweenStorage( $result = true; } if (is_resource($dh)) { - while ($result and ($file = readdir($dh)) !== false) { + while ($result && ($file = readdir($dh)) !== false) { if (!Filesystem::isIgnoredDir($file)) { $result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file, false, $isRename); } } + closedir($dh); } } else { try { diff --git a/lib/private/TempManager.php b/lib/private/TempManager.php index 0df31dce3fff1..4924377a2fc1c 100644 --- a/lib/private/TempManager.php +++ b/lib/private/TempManager.php @@ -189,7 +189,7 @@ protected function getOldFiles() { $cutOfTime = time() - 3600; $files = []; $dh = opendir($this->tmpBaseDir); - if ($dh) { + if (is_resource($dh)) { while (($file = readdir($dh)) !== false) { if (substr($file, 0, 7) === self::TMP_PREFIX) { $path = $this->tmpBaseDir . '/' . $file; @@ -199,6 +199,7 @@ protected function getOldFiles() { } } } + closedir($dh); } return $files; } diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index 23e0b099e9112..d74a27295f58f 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -523,10 +523,11 @@ public static function getAllApps(): array { if (is_resource($dh)) { while (($file = readdir($dh)) !== false) { - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { + if ($file[0] != '.' && is_dir($apps_dir['path'] . '/' . $file) && is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { $apps[] = $file; } } + closedir($dh); } } diff --git a/tests/apps.php b/tests/apps.php index cd173fff5d5e9..a3f8e242be637 100644 --- a/tests/apps.php +++ b/tests/apps.php @@ -31,6 +31,7 @@ function loadDirectory($path): void { require_once $file; } } + closedir($dh); } function getSubclasses($parentClassName): array { diff --git a/tests/lib/Files/Storage/Storage.php b/tests/lib/Files/Storage/Storage.php index a646fd5fd0ba4..005ac0c8826a4 100644 --- a/tests/lib/Files/Storage/Storage.php +++ b/tests/lib/Files/Storage/Storage.php @@ -82,10 +82,11 @@ public function testDirectories($directory) { $dh = $this->instance->opendir('/'); $content = []; while ($file = readdir($dh)) { - if ($file != '.' and $file != '..') { + if ($file != '.' && $file != '..') { $content[] = $file; } } + closedir($dh); $this->assertEquals([$directory], $content); $content = iterator_to_array($this->instance->getDirectoryContent('/')); @@ -114,10 +115,11 @@ public function testDirectories($directory) { $dh = $this->instance->opendir('/'); $content = []; while ($file = readdir($dh)) { - if ($file != '.' and $file != '..') { + if ($file != '.' && $file != '..') { $content[] = $file; } } + closedir($dh); $this->assertEquals([], $content); } @@ -455,10 +457,11 @@ public function testHashInFileName() { $dh = $this->instance->opendir('#foo'); $content = []; while ($file = readdir($dh)) { - if ($file != '.' and $file != '..') { + if ($file != '.' && $file != '..') { $content[] = $file; } } + closedir($dh); $this->assertEquals(['test.txt'], $content); } diff --git a/tests/lib/Files/Storage/Wrapper/JailTest.php b/tests/lib/Files/Storage/Wrapper/JailTest.php index 148bd3a4f30c2..dc1e1fe4cea8c 100644 --- a/tests/lib/Files/Storage/Wrapper/JailTest.php +++ b/tests/lib/Files/Storage/Wrapper/JailTest.php @@ -33,6 +33,7 @@ protected function tearDown(): void { $contents[] = $file; } } + closedir($dh); $this->assertEquals(['foo'], $contents); $this->sourceStorage->cleanUp(); parent::tearDown();