From 14f6030140eebed1d439ebd62c79c224c2405196 Mon Sep 17 00:00:00 2001 From: Julius Härtl Date: Fri, 10 Jan 2020 13:06:27 +0100 Subject: CHeck if file already exists during file creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl Signed-off-by: Roeland Jago Douma --- lib/private/DirectEditing/Manager.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php index a514eaea482..ebca819eeae 100644 --- a/lib/private/DirectEditing/Manager.php +++ b/lib/private/DirectEditing/Manager.php @@ -123,15 +123,21 @@ class Manager implements IManager { public function create(string $path, string $editorId, string $creatorId, $templateId = null): string { $userFolder = $this->rootFolder->getUserFolder($this->userId); - $file = $userFolder->newFile($path); - $editor = $this->getEditor($editorId); - $creators = $editor->getCreators(); - foreach ($creators as $creator) { - if ($creator->getId() === $creatorId) { - $creator->create($file, $creatorId, $templateId); - return $this->createToken($editorId, $file, $path); + try { + $file = $userFolder->get($path); + throw new \RuntimeException('File already exists'); + } catch (\OCP\Files\NotFoundException $e) { + $file = $userFolder->newFile($path); + $editor = $this->getEditor($editorId); + $creators = $editor->getCreators(); + foreach ($creators as $creator) { + if ($creator->getId() === $creatorId) { + $creator->create($file, $creatorId, $templateId); + return $this->createToken($editorId, $file, $path); + } } } + throw new \RuntimeException('No creator found'); } -- cgit v1.2.3