From eea1c237197a1dcdf4ee0cf3de9c94b2683aba40 Mon Sep 17 00:00:00 2001 From: acsfer Date: Wed, 9 Jun 2021 14:38:21 +0200 Subject: [PATCH 1/3] Handle files with is_file instead of file_exists Should fix things like `fread(): read of 8192 bytes failed with errno=21 Is a directory` --- lib/private/Files/Storage/Wrapper/Encryption.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 125338a290dfc..ef5697cdd2435 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -391,7 +391,7 @@ public function fopen($path, $mode) { if ($this->util->isExcluded($fullPath) === false) { $size = $unencryptedSize = 0; $realFile = $this->util->stripPartialFileExtension($path); - $targetExists = $this->file_exists($realFile) || $this->file_exists($path); + $targetExists = $this->is_file($realFile) || $this->file_exists($path); $targetIsEncrypted = false; if ($targetExists) { // in case the file exists we require the explicit module as @@ -855,7 +855,7 @@ protected function getFullPath($path) { */ protected function readFirstBlock($path) { $firstBlock = ''; - if ($this->storage->file_exists($path)) { + if ($this->storage->is_file($path)) { $handle = $this->storage->fopen($path, 'r'); $firstBlock = fread($handle, $this->util->getHeaderSize()); fclose($handle); @@ -872,7 +872,7 @@ protected function readFirstBlock($path) { protected function getHeaderSize($path) { $headerSize = 0; $realFile = $this->util->stripPartialFileExtension($path); - if ($this->storage->file_exists($realFile)) { + if ($this->storage->is_file($realFile)) { $path = $realFile; } $firstBlock = $this->readFirstBlock($path); @@ -920,7 +920,7 @@ protected function parseRawHeader($rawHeader) { */ protected function getHeader($path) { $realFile = $this->util->stripPartialFileExtension($path); - $exists = $this->storage->file_exists($realFile); + $exists = $this->storage->is_file($realFile); if ($exists) { $path = $realFile; } From b3482b1d062679274d1fccee03c9aa10f00fc240 Mon Sep 17 00:00:00 2001 From: acsfer Date: Sun, 15 Aug 2021 12:23:29 +0200 Subject: [PATCH 2/3] Tests update --- tests/lib/Files/Storage/Wrapper/EncryptionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php index a4ee5e45bd5fb..73e9192d4adec 100644 --- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php @@ -624,7 +624,7 @@ public function testGetHeader($path, $strippedPathExists, $strippedPath) { $util->expects($this->once())->method('stripPartialFileExtension') ->with($path)->willReturn($strippedPath); $sourceStorage->expects($this->once()) - ->method('file_exists') + ->method('is_file') ->with($strippedPath) ->willReturn($strippedPathExists); From 8610099c5f888bf07b2904031b6ee7968a34e77b Mon Sep 17 00:00:00 2001 From: acsfer Date: Fri, 22 Oct 2021 12:16:11 +0200 Subject: [PATCH 3/3] Update Tests --- tests/lib/Files/Storage/Wrapper/EncryptionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php index 73e9192d4adec..71af8fb7ece3a 100644 --- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php @@ -652,7 +652,7 @@ public function testGetHeaderAddLegacyModule($header, $isEncrypted, $exists, $ex ->disableOriginalConstructor()->getMock(); $sourceStorage->expects($this->once()) - ->method('file_exists') + ->method('is_file') ->willReturn($exists); $util = $this->getMockBuilder('\OC\Encryption\Util')