From 6674f790a9eb81570b887719d1e29b2c1bcbe7a6 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Mon, 1 Jul 2024 16:52:23 +0200 Subject: [PATCH 1/2] fix(files): Ensure that the hash method does not return null To match https://github.com/nextcloud/server/blob/beececf66068f57c416225efcde9b44ce5c2e835/lib/private/Files/View.php#L1050 - Fix https://github.com/nextcloud/server/issues/44110 Signed-off-by: Louis Chemineau --- lib/private/Files/Storage/Local.php | 11 +++++++++-- lib/private/Files/Storage/Wrapper/Availability.php | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index 811a000ad6f9c..ec4fd84ebe2c0 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -400,8 +400,15 @@ public function fopen($path, $mode) { return $result; } - public function hash($type, $path, $raw = false) { - return hash_file($type, $this->getSourcePath($path), $raw); + public function hash($type, $path, $raw = false): string|false { + /** @var string|false|null */ + $hash = hash_file($type, $this->getSourcePath($path), $raw); + + if ($hash === null) { + return false; + } + + return $hash; } public function free_space($path) { diff --git a/lib/private/Files/Storage/Wrapper/Availability.php b/lib/private/Files/Storage/Wrapper/Availability.php index 149cbbaa33b8f..6bd622e1c1bb1 100644 --- a/lib/private/Files/Storage/Wrapper/Availability.php +++ b/lib/private/Files/Storage/Wrapper/Availability.php @@ -315,6 +315,7 @@ public function hash($type, $path, $raw = false) { return parent::hash($type, $path, $raw); } catch (StorageNotAvailableException $e) { $this->setUnavailable($e); + return false; } } From 9acaf0788f9fb0a1f60d7c6566a46f73a83c87e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Mon, 16 Sep 2024 11:32:29 +0200 Subject: [PATCH 2/2] chore: improve hash_file php usage in Local Storage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ferdinand Thiessen Signed-off-by: John Molakvoæ --- lib/private/Files/Storage/Local.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index ec4fd84ebe2c0..c550cf75bc69c 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -401,14 +401,7 @@ public function fopen($path, $mode) { } public function hash($type, $path, $raw = false): string|false { - /** @var string|false|null */ - $hash = hash_file($type, $this->getSourcePath($path), $raw); - - if ($hash === null) { - return false; - } - - return $hash; + return hash_file($type, $this->getSourcePath($path), $raw); } public function free_space($path) {