diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-01-15 12:24:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-15 12:24:06 +0100 |
commit | 7a79e9525452d50900c0df9b314d7a0de19f625c (patch) | |
tree | d877a1f284a3db8c453a72a7822f574932b9da32 /lib | |
parent | 4a059829837cef1ca065e68516161963952f7fdc (diff) | |
parent | 14f6030140eebed1d439ebd62c79c224c2405196 (diff) | |
download | nextcloud-server-7a79e9525452d50900c0df9b314d7a0de19f625c.tar.gz nextcloud-server-7a79e9525452d50900c0df9b314d7a0de19f625c.zip |
Merge pull request #18878 from nextcloud/backport/18805/stable18
[stable18] Check if file already exists during file creation
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/DirectEditing/Manager.php | 20 |
1 files changed, 13 insertions, 7 deletions
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'); } |