From 9d5c5eb1a35dc9314055d773bf145c3b4a49b48a Mon Sep 17 00:00:00 2001 From: Ronny Bremer Date: Mon, 19 May 2025 12:13:43 +0200 Subject: [PATCH] adopted documentation on how to create a new file or override an existing file previous code was outdated and didn't work anymore in newer NC versions (possibly since NC 29) Signed-off-by: Ronny Bremer --- developer_manual/basics/storage/filesystem.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/developer_manual/basics/storage/filesystem.rst b/developer_manual/basics/storage/filesystem.rst index 2bb304933..2f346f8c9 100644 --- a/developer_manual/basics/storage/filesystem.rst +++ b/developer_manual/basics/storage/filesystem.rst @@ -81,13 +81,12 @@ All methods return a Folder object on which files and folders can be accessed, o try { try { $file = $userFolder->get('myfile.txt'); - } catch(\OCP\Files\NotFoundException $e) { - $userFolder->touch('myfile.txt'); - $file = $userFolder->get('myfile.txt'); - } - // the id can be accessed by $file->getId(); - $file->putContent($content); + // the id can be accessed by $file->getId(); + $file->putContent($content); + } catch(\OCP\Files\NotFoundException $e) { + $userFolder->newFile('myfile.txt', $content); + } } catch(\OCP\Files\NotPermittedException $e) { // you have to create this exception by yourself ;) @@ -163,4 +162,4 @@ The recommended way of adding your own mounts to the filesystem from an app is i and registering the provider using ``OCP\Files\Config\IMountProviderCollection::registerProvider``. Once registered, your provider will be called every time the filesystem is being setup for a user and your mount provider -can return a list of mounts to add for that user. \ No newline at end of file +can return a list of mounts to add for that user.