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>
pull/37943/head
Côme Chilliet 3 years ago
parent 5e96228eb1
commit 546d94c3ec
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
  1. 2
      lib/private/Files/Filesystem.php
  2. 12
      lib/private/Files/Node/File.php
  3. 2
      lib/private/Files/Storage/Wrapper/Encoding.php
  4. 2
      lib/private/Files/Storage/Wrapper/Encryption.php
  5. 2
      lib/private/Files/Storage/Wrapper/Jail.php
  6. 2
      lib/private/Files/Storage/Wrapper/Wrapper.php
  7. 2
      lib/private/Files/View.php
  8. 1
      lib/public/Files/File.php
  9. 2
      lib/public/Files/Storage.php
  10. 2
      lib/public/Files/Storage/IStorage.php

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save