Fix file_get_content signatures to make it clear it can return false

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>
This commit is contained in:
Côme Chilliet 2023-04-27 09:56:05 +02:00
parent 5e96228eb1
commit 546d94c3ec
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A
10 changed files with 16 additions and 13 deletions

View 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);

View 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) {

View 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));

View 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);

View 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));

View 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);

View file

@ -564,7 +564,7 @@ class View {
/**
* @param string $path
* @return mixed
* @return string|false
* @throws LockedException
*/
public function file_get_contents($path) {

View file

@ -40,6 +40,7 @@ interface File extends Node {
*
* @return string
* @throws NotPermittedException
* @throws GenericFileException
* @throws LockedException
* @since 6.0.0
*/

View 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);

View 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);