diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-01-10 13:06:27 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2020-01-13 18:10:12 +0100 |
commit | ab4b9a6df5b031174f4e3bdd62069d7ec26c6066 (patch) | |
tree | b002a555d0bbafbe213032fef00cc236a47a2e9a /lib/private | |
parent | edd957140ad35e5e679084246dfb67eaca584119 (diff) | |
download | nextcloud-server-ab4b9a6df5b031174f4e3bdd62069d7ec26c6066.tar.gz nextcloud-server-ab4b9a6df5b031174f4e3bdd62069d7ec26c6066.zip |
CHeck if file already exists during file creation
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private')
-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'); } |