Skip to content

Commit 997efe4

Browse files
authored
Merge pull request #37943 from nextcloud/fix/fix-getcontent-return-type
Fix file_get_content signatures to make it clear it can return false
2 parents 7fcf42a + 546d94c commit 997efe4

File tree

10 files changed

+16
-13
lines changed

10 files changed

+16
-13
lines changed

lib/private/Files/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ public static function touch($path, $mtime = null) {
554554
}
555555

556556
/**
557-
* @return string
557+
* @return string|false
558558
*/
559559
public static function file_get_contents($path) {
560560
return self::$defaultInstance->file_get_contents($path);

lib/private/Files/Node/File.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ protected function createNonExistingNode($path) {
4646
/**
4747
* @return string
4848
* @throws NotPermittedException
49+
* @throws GenericFileException
4950
* @throws LockedException
5051
*/
5152
public function getContent() {
5253
if ($this->checkPermissions(\OCP\Constants::PERMISSION_READ)) {
53-
/**
54-
* @var \OC\Files\Storage\Storage $storage;
55-
*/
56-
return $this->view->file_get_contents($this->path);
54+
$content = $this->view->file_get_contents($this->path);
55+
if ($content === false) {
56+
throw new GenericFileException();
57+
}
58+
return $content;
5759
} else {
5860
throw new NotPermittedException();
5961
}
@@ -62,7 +64,7 @@ public function getContent() {
6264
/**
6365
* @param string|resource $data
6466
* @throws NotPermittedException
65-
* @throws \OCP\Files\GenericFileException
67+
* @throws GenericFileException
6668
* @throws LockedException
6769
*/
6870
public function putContent($data) {

lib/private/Files/Storage/Wrapper/Encoding.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public function filemtime($path) {
300300
* see https://www.php.net/manual/en/function.file_get_contents.php
301301
*
302302
* @param string $path
303-
* @return string|bool
303+
* @return string|false
304304
*/
305305
public function file_get_contents($path) {
306306
return $this->storage->file_get_contents($this->findPathToUse($path));

lib/private/Files/Storage/Wrapper/Encryption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function getDirectoryContent($directory): \Traversable {
217217
* see https://www.php.net/manual/en/function.file_get_contents.php
218218
*
219219
* @param string $path
220-
* @return string
220+
* @return string|false
221221
*/
222222
public function file_get_contents($path) {
223223
$encryptionModule = $this->getEncryptionModule($path);

lib/private/Files/Storage/Wrapper/Jail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function filemtime($path) {
248248
* see https://www.php.net/manual/en/function.file_get_contents.php
249249
*
250250
* @param string $path
251-
* @return string|bool
251+
* @return string|false
252252
*/
253253
public function file_get_contents($path) {
254254
return $this->getWrapperStorage()->file_get_contents($this->getUnjailedPath($path));

lib/private/Files/Storage/Wrapper/Wrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function filemtime($path) {
238238
* see https://www.php.net/manual/en/function.file_get_contents.php
239239
*
240240
* @param string $path
241-
* @return string|bool
241+
* @return string|false
242242
*/
243243
public function file_get_contents($path) {
244244
return $this->getWrapperStorage()->file_get_contents($path);

lib/private/Files/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ public function touch($path, $mtime = null): bool {
564564

565565
/**
566566
* @param string $path
567-
* @return mixed
567+
* @return string|false
568568
* @throws LockedException
569569
*/
570570
public function file_get_contents($path) {

lib/public/Files/File.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface File extends Node {
4040
*
4141
* @return string
4242
* @throws NotPermittedException
43+
* @throws GenericFileException
4344
* @throws LockedException
4445
* @since 6.0.0
4546
*/

lib/public/Files/Storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function filemtime($path);
217217
* see https://www.php.net/manual/en/function.file_get_contents.php
218218
*
219219
* @param string $path
220-
* @return string|bool
220+
* @return string|false
221221
* @since 6.0.0
222222
*/
223223
public function file_get_contents($path);

lib/public/Files/Storage/IStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function filemtime($path);
214214
* see https://www.php.net/manual/en/function.file_get_contents.php
215215
*
216216
* @param string $path
217-
* @return string|bool
217+
* @return string|false
218218
* @since 9.0.0
219219
*/
220220
public function file_get_contents($path);

0 commit comments

Comments
 (0)