From 63608ef461eef289cfc97d1eb5ff63aac3848bea Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 18 Feb 2020 18:02:58 +0100 Subject: [PATCH] allow writing content directly when creating new SimpleFile Signed-off-by: Robin Appelman --- lib/private/Files/SimpleFS/NewSimpleFile.php | 2 +- lib/private/Files/SimpleFS/SimpleFolder.php | 11 ++++++++--- lib/public/Files/Folder.php | 2 +- lib/public/Files/SimpleFS/ISimpleFolder.php | 3 ++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/private/Files/SimpleFS/NewSimpleFile.php b/lib/private/Files/SimpleFS/NewSimpleFile.php index 02dde1d2f8..2c74a16fa9 100644 --- a/lib/private/Files/SimpleFS/NewSimpleFile.php +++ b/lib/private/Files/SimpleFS/NewSimpleFile.php @@ -123,7 +123,7 @@ class NewSimpleFile implements ISimpleFile { public function putContent($data) { try { if ($this->file) { - return $this->file->putContent($data); + $this->file->putContent($data); } else { $this->file = $this->parentFolder->newFile($this->name, $data); } diff --git a/lib/private/Files/SimpleFS/SimpleFolder.php b/lib/private/Files/SimpleFS/SimpleFolder.php index 76f6a198e2..a4ebc6b4e5 100644 --- a/lib/private/Files/SimpleFS/SimpleFolder.php +++ b/lib/private/Files/SimpleFS/SimpleFolder.php @@ -80,8 +80,13 @@ class SimpleFolder implements ISimpleFolder { return new SimpleFile($file); } - public function newFile($name) { - // delay creating the file until it's written to - return new NewSimpleFile($this->folder, $name); + public function newFile($name, $content = null) { + if ($content === null) { + // delay creating the file until it's written to + return new NewSimpleFile($this->folder, $name); + } else { + $file = $this->folder->newFile($name, $content); + return new SimpleFile($file); + } } } diff --git a/lib/public/Files/Folder.php b/lib/public/Files/Folder.php index e7286ea028..a78a9ca8f7 100644 --- a/lib/public/Files/Folder.php +++ b/lib/public/Files/Folder.php @@ -109,7 +109,7 @@ interface Folder extends Node { * Create a new file * * @param string $path relative path of the new file - * @param string | resource | null $content content for the new file, since 19.0.0 + * @param string|resource|null $content content for the new file, since 19.0.0 * @return \OCP\Files\File * @throws \OCP\Files\NotPermittedException * @since 6.0.0 diff --git a/lib/public/Files/SimpleFS/ISimpleFolder.php b/lib/public/Files/SimpleFS/ISimpleFolder.php index e3ef2bb48c..22f8c90849 100644 --- a/lib/public/Files/SimpleFS/ISimpleFolder.php +++ b/lib/public/Files/SimpleFS/ISimpleFolder.php @@ -64,11 +64,12 @@ interface ISimpleFolder { * Creates a new file with $name in the folder * * @param string $name + * @param string|resource|null $content @since 19.0.0 * @return ISimpleFile * @throws NotPermittedException * @since 11.0.0 */ - public function newFile($name); + public function newFile($name, $content = null); /** * Remove the folder and all the files in it