]> source.dussan.org Git - nextcloud-server.git/commitdiff
allow writing content directly when creating new SimpleFile
authorRobin Appelman <robin@icewind.nl>
Tue, 18 Feb 2020 17:02:58 +0000 (18:02 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Fri, 28 Feb 2020 11:55:22 +0000 (12:55 +0100)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/SimpleFS/NewSimpleFile.php
lib/private/Files/SimpleFS/SimpleFolder.php
lib/public/Files/Folder.php
lib/public/Files/SimpleFS/ISimpleFolder.php

index 02dde1d2f883dfe6316f9f1ddfb3f79b978fb755..2c74a16fa922180a7992a20206023ededef3a0b3 100644 (file)
@@ -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);
                        }
index 76f6a198e2520c5f770ae195c24221a6b8bc01c0..a4ebc6b4e539d29179cd75299718430a32f6dcb3 100644 (file)
@@ -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);
+               }
        }
 }
index e7286ea028c32d755cfa5381aed34500c0ab698c..a78a9ca8f78ad15503315863e8f939d864c26b9d 100644 (file)
@@ -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
index e3ef2bb48cd0e5b4620cbf6a324cf0d697dbcd32..22f8c90849b11d1cb5f44cca8d8233562c070a77 100644 (file)
@@ -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