diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 7cbfa8a126a..78a96c57296 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -813,6 +813,8 @@ class Encryption extends Wrapper { } } } else { + $source = false; + $target = false; try { $source = $sourceStorage->fopen($sourceInternalPath, 'r'); $target = $this->fopen($targetInternalPath, 'w'); @@ -822,10 +824,10 @@ class Encryption extends Wrapper { [, $result] = \OC_Helper::streamCopy($source, $target); } } finally { - if (isset($source) && $source !== false) { + if ($source !== false) { fclose($source); } - if (isset($target) && $target !== false) { + if ($target !== false) { fclose($target); } } diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index edda380b549..bec27b228ed 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -1183,6 +1183,9 @@ class ViewTest extends \Test\TestCase { $storage2->method('writeStream') ->willThrowException(new GenericFileException('Failed to copy stream')); + $storage2->method('fopen') + ->willReturn(false); + $storage1->mkdir('sub'); $storage1->file_put_contents('foo.txt', '0123456789ABCDEFGH'); $storage1->mkdir('dirtomove');