Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly close the directory stream #41013

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/encryption/lib/Command/FixKeyLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ private function findKeysByFileName(string $basePath, string $name) {
}
}
}
closedir($dh);
}
}

Expand Down
1 change: 1 addition & 0 deletions apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ public static function isEmpty($user) {
return false;
}
}
closedir($dh);
}
return true;
}
Expand Down
1 change: 1 addition & 0 deletions lib/private/Archive/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public function addRecursive(string $path, string $source): void {
$this->addFile($path.'/'.$file, $source.'/'.$file);
}
}
closedir($dh);
}
}
}
8 changes: 5 additions & 3 deletions lib/private/Cache/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -200,6 +201,7 @@ public function gc() {
}
}
}
closedir($dh);
}
}

Expand Down
5 changes: 4 additions & 1 deletion lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ private function addLocalFolder($path, $target) {
}
}
}
closedir($dh);
}
}

Expand All @@ -317,8 +318,8 @@ protected function searchInDir($query, $dir = '') {
$files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item));
}
}
closedir($dh);
}
closedir($dh);
return $files;
}

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -905,6 +907,7 @@ public function getDirectoryContent($directory): \Traversable {
}
}
}
closedir($dh);
}
}
}
3 changes: 2 additions & 1 deletion lib/private/Files/Storage/Wrapper/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion lib/private/TempManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -199,6 +199,7 @@ protected function getOldFiles() {
}
}
}
closedir($dh);
}
return $files;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/apps.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function loadDirectory($path): void {
require_once $file;
}
}
closedir($dh);
}

function getSubclasses($parentClassName): array {
Expand Down
9 changes: 6 additions & 3 deletions tests/lib/Files/Storage/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/'));
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions tests/lib/Files/Storage/Wrapper/JailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function tearDown(): void {
$contents[] = $file;
}
}
closedir($dh);
$this->assertEquals(['foo'], $contents);
$this->sourceStorage->cleanUp();
parent::tearDown();
Expand Down
Loading