]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix file_get_content signatures to make it clear it can return false 37943/head
authorCôme Chilliet <come.chilliet@nextcloud.com>
Thu, 27 Apr 2023 07:56:05 +0000 (09:56 +0200)
committerCôme Chilliet <come.chilliet@nextcloud.com>
Thu, 27 Apr 2023 07:56:05 +0000 (09:56 +0200)
In File::getContent, which must return a string, throw an Exception
 instead of returning false.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
lib/private/Files/Filesystem.php
lib/private/Files/Node/File.php
lib/private/Files/Storage/Wrapper/Encoding.php
lib/private/Files/Storage/Wrapper/Encryption.php
lib/private/Files/Storage/Wrapper/Jail.php
lib/private/Files/Storage/Wrapper/Wrapper.php
lib/private/Files/View.php
lib/public/Files/File.php
lib/public/Files/Storage.php
lib/public/Files/Storage/IStorage.php

index c50fa1f9de98f447fa5b01e93dc98c1c001d3795..2eab4c58a0c6af6f9fc7662d49f429e193edb8f3 100644 (file)
@@ -554,7 +554,7 @@ class Filesystem {
        }
 
        /**
-        * @return string
+        * @return string|false
         */
        public static function file_get_contents($path) {
                return self::$defaultInstance->file_get_contents($path);
index 27056efef72b418ce1e504f9b3c9f46e8fd21e47..b6cd65716510bf00812a0516293c732ef49285c5 100644 (file)
@@ -46,14 +46,16 @@ class File extends Node implements \OCP\Files\File {
        /**
         * @return string
         * @throws NotPermittedException
+        * @throws GenericFileException
         * @throws LockedException
         */
        public function getContent() {
                if ($this->checkPermissions(\OCP\Constants::PERMISSION_READ)) {
-                       /**
-                        * @var \OC\Files\Storage\Storage $storage;
-                        */
-                       return $this->view->file_get_contents($this->path);
+                       $content = $this->view->file_get_contents($this->path);
+                       if ($content === false) {
+                               throw new GenericFileException();
+                       }
+                       return $content;
                } else {
                        throw new NotPermittedException();
                }
@@ -62,7 +64,7 @@ class File extends Node implements \OCP\Files\File {
        /**
         * @param string|resource $data
         * @throws NotPermittedException
-        * @throws \OCP\Files\GenericFileException
+        * @throws GenericFileException
         * @throws LockedException
         */
        public function putContent($data) {
index dd699993e841b3f6f009bcf7e3ea4069c7bf52d6..6633cbf41e34024dd8c648a4a5ed416c97d1ed95 100644 (file)
@@ -300,7 +300,7 @@ class Encoding extends Wrapper {
         * see https://www.php.net/manual/en/function.file_get_contents.php
         *
         * @param string $path
-        * @return string|bool
+        * @return string|false
         */
        public function file_get_contents($path) {
                return $this->storage->file_get_contents($this->findPathToUse($path));
index 720111793deac553e08098fcf31b2c24b7b49bea..9c0e6c91463964dd2c95e1bd5251a3be6b08ff37 100644 (file)
@@ -217,7 +217,7 @@ class Encryption extends Wrapper {
         * see https://www.php.net/manual/en/function.file_get_contents.php
         *
         * @param string $path
-        * @return string
+        * @return string|false
         */
        public function file_get_contents($path) {
                $encryptionModule = $this->getEncryptionModule($path);
index 619d8b07137c8575efaeec282743eadb7d305fec..caf039d4cca05e06d712095b792822b1f298dbc4 100644 (file)
@@ -248,7 +248,7 @@ class Jail extends Wrapper {
         * see https://www.php.net/manual/en/function.file_get_contents.php
         *
         * @param string $path
-        * @return string|bool
+        * @return string|false
         */
        public function file_get_contents($path) {
                return $this->getWrapperStorage()->file_get_contents($this->getUnjailedPath($path));
index 28a1e0b1e4da5a3ae0e572fea9c0e9e50fa1273b..9f5564b449038ee20ce3132d466d9312133d4a46 100644 (file)
@@ -238,7 +238,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea
         * see https://www.php.net/manual/en/function.file_get_contents.php
         *
         * @param string $path
-        * @return string|bool
+        * @return string|false
         */
        public function file_get_contents($path) {
                return $this->getWrapperStorage()->file_get_contents($path);
index 91e6cc2d60e0c80009678cb4caa68c5f4466af50..5970c213210a7028a036c620c671162b3181be1e 100644 (file)
@@ -564,7 +564,7 @@ class View {
 
        /**
         * @param string $path
-        * @return mixed
+        * @return string|false
         * @throws LockedException
         */
        public function file_get_contents($path) {
index 93d0ab860c1e295cfef36a7904915a720b069843..7c1e36cb3ebde82dc198daee80e2db390f9c1898 100644 (file)
@@ -40,6 +40,7 @@ interface File extends Node {
         *
         * @return string
         * @throws NotPermittedException
+        * @throws GenericFileException
         * @throws LockedException
         * @since 6.0.0
         */
index c165266a1b72a4b048d704acb9b795b25700280a..31405a26bfa635417b6aea8725b6e0ac389289ab 100644 (file)
@@ -217,7 +217,7 @@ interface Storage extends IStorage {
         * see https://www.php.net/manual/en/function.file_get_contents.php
         *
         * @param string $path
-        * @return string|bool
+        * @return string|false
         * @since 6.0.0
         */
        public function file_get_contents($path);
index 2f38165830bbeeeb8dfaa2732e2728c0f6e54642..00e98fdfbb6e6a0cfdf58978c0ec9e916d06dfdb 100644 (file)
@@ -214,7 +214,7 @@ interface IStorage {
         * see https://www.php.net/manual/en/function.file_get_contents.php
         *
         * @param string $path
-        * @return string|bool
+        * @return string|false
         * @since 9.0.0
         */
        public function file_get_contents($path);