Skip to content

Commit

Permalink
Explicitly close the directory stream
Browse files Browse the repository at this point in the history
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Close the stream

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Close the stream

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Close the stream

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Close the stream

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Close the stream

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Close the stream

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Close the stream

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Close the stream

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Close the stream

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Close the stream

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
  • Loading branch information
solracsf committed Oct 20, 2023
1 parent e49353d commit c61afb1
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 10 deletions.
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) {

Check failure on line 193 in lib/private/TempManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParseError

lib/private/TempManager.php:193:4: ParseError: Syntax error, unexpected T_WHILE on line 193 (see https://psalm.dev/173)
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;

Check failure on line 204 in lib/private/TempManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParseError

lib/private/TempManager.php:204:3: ParseError: Syntax error, unexpected T_RETURN on line 204 (see https://psalm.dev/173)
}
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

0 comments on commit c61afb1

Please sign in to comment.