mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #28907 from nextcloud/bug/noid/close-stream-local
explicitly close source stream on local / encryption storage
This commit is contained in:
commit
9187e986e1
3 changed files with 9 additions and 4 deletions
|
|
@ -568,8 +568,11 @@ class Local extends \OC\Files\Storage\Common {
|
|||
|
||||
public function writeStream(string $path, $stream, int $size = null): int {
|
||||
$result = $this->file_put_contents($path, $stream);
|
||||
if (is_resource($stream)) {
|
||||
fclose($stream);
|
||||
}
|
||||
if ($result === false) {
|
||||
throw new GenericFileException("Failed write steam to $path");
|
||||
throw new GenericFileException("Failed write stream to $path");
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -926,10 +926,10 @@ class Encryption extends Wrapper {
|
|||
}
|
||||
|
||||
$result = [];
|
||||
|
||||
|
||||
// first check if it is an encrypted file at all
|
||||
// We would do query to filecache only if we know that entry in filecache exists
|
||||
|
||||
|
||||
$info = $this->getCache()->get($path);
|
||||
if (isset($info['encrypted']) && $info['encrypted'] === true) {
|
||||
$firstBlock = $this->readFirstBlock($path);
|
||||
|
|
@ -1033,6 +1033,7 @@ class Encryption extends Wrapper {
|
|||
// always fall back to fopen
|
||||
$target = $this->fopen($path, 'w');
|
||||
[$count, $result] = \OC_Helper::streamCopy($stream, $target);
|
||||
fclose($stream);
|
||||
fclose($target);
|
||||
return $count;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -658,6 +658,7 @@ abstract class Storage extends \Test\TestCase {
|
|||
|
||||
$storage->writeStream('test.txt', $source);
|
||||
$this->assertTrue($storage->file_exists('test.txt'));
|
||||
$this->assertEquals(file_get_contents($textFile), $storage->file_get_contents('test.txt'));
|
||||
$this->assertStringEqualsFile($textFile, $storage->file_get_contents('test.txt'));
|
||||
$this->assertEquals('resource (closed)', gettype($source));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue