From 71ef42606f18e5397bb0d7b1983d12cc2e9cf90a Mon Sep 17 00:00:00 2001 From: Damian Glinkowski Date: Fri, 12 Jun 2020 19:37:13 +0200 Subject: [PATCH] Fix create SimpleFile with empty content After that change https://github.com/nextcloud/server/pull/19493 where you have to provide content to method `newFile` is a bug with empty `''` content. Php function `file_put_contents` will returns the numbers of bytes that written to the file, or `FALSE` on failure https://www.php.net/manual/en/function.file-put-contents.php So for empty `''` content it will return `0` which is `true` for this statement: ``` if (!$result) { throw new NotPermittedException('Could not create path'); } ``` From now empty content will not throws an exception. --- lib/private/Files/Node/Folder.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index d9639e9f1abf9..49e5b39ebb6d1 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -185,6 +185,9 @@ public function newFile($path, $content = null) { $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]); if ($content !== null) { $result = $this->view->file_put_contents($fullPath, $content); + if ($content === '' && $result === 0) { + $result = true; + } } else { $result = $this->view->touch($fullPath); }