Skip to content

Commit

Permalink
Merge pull request #37943 from nextcloud/fix/fix-getcontent-return-type
Browse files Browse the repository at this point in the history
Fix file_get_content signatures to make it clear it can return false
  • Loading branch information
blizzz authored May 3, 2023
2 parents 7fcf42a + 546d94c commit 997efe4
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/private/Files/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public static function touch($path, $mtime = null) {
}

/**
* @return string
* @return string|false
*/
public static function file_get_contents($path) {
return self::$defaultInstance->file_get_contents($path);
Expand Down
12 changes: 7 additions & 5 deletions lib/private/Files/Node/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ protected function createNonExistingNode($path) {
/**
* @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();
}
Expand All @@ -62,7 +64,7 @@ public function getContent() {
/**
* @param string|resource $data
* @throws NotPermittedException
* @throws \OCP\Files\GenericFileException
* @throws GenericFileException
* @throws LockedException
*/
public function putContent($data) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/Wrapper/Encoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function filemtime($path) {
* 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));
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/Wrapper/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function getDirectoryContent($directory): \Traversable {
* 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);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/Wrapper/Jail.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function filemtime($path) {
* 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));
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/Wrapper/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function filemtime($path) {
* 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);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ public function touch($path, $mtime = null): bool {

/**
* @param string $path
* @return mixed
* @return string|false
* @throws LockedException
*/
public function file_get_contents($path) {
Expand Down
1 change: 1 addition & 0 deletions lib/public/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface File extends Node {
*
* @return string
* @throws NotPermittedException
* @throws GenericFileException
* @throws LockedException
* @since 6.0.0
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Files/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function filemtime($path);
* 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);
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Files/Storage/IStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function filemtime($path);
* 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);
Expand Down

0 comments on commit 997efe4

Please sign in to comment.