diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-01-14 23:36:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-14 23:36:59 +0100 |
commit | ec0d8b8de0270ea739f74a1eb18633329c5e79ca (patch) | |
tree | 6491efaebbe7c82ff09f951f53011f90540208ac | |
parent | 510a29f871ded9c84ca9d24dea4c9623d1c5ae73 (diff) | |
parent | 47fd6730e0da7d15d5cd0ef550ce2c957208f8eb (diff) | |
download | nextcloud-server-ec0d8b8de0270ea739f74a1eb18633329c5e79ca.tar.gz nextcloud-server-ec0d8b8de0270ea739f74a1eb18633329c5e79ca.zip |
Merge pull request #18886 from nextcloud/node_exists-instead-of-catch
use `nodeExists` instead of catching exceptions
-rw-r--r-- | lib/private/DirectEditing/Manager.php | 5 | ||||
-rw-r--r-- | tests/lib/DirectEditing/ManagerTest.php | 12 |
2 files changed, 10 insertions, 7 deletions
diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php index ac85e62cb72..5e3f7755938 100644 --- a/lib/private/DirectEditing/Manager.php +++ b/lib/private/DirectEditing/Manager.php @@ -124,10 +124,9 @@ class Manager implements IManager { public function create(string $path, string $editorId, string $creatorId, $templateId = null): string { $userFolder = $this->rootFolder->getUserFolder($this->userId); - try { - $file = $userFolder->get($path); + if ($userFolder->nodeExists($path)) { throw new \RuntimeException('File already exists'); - } catch (\OCP\Files\NotFoundException $e) { + } else { $file = $userFolder->newFile($path); $editor = $this->getEditor($editorId); $creators = $editor->getCreators(); diff --git a/tests/lib/DirectEditing/ManagerTest.php b/tests/lib/DirectEditing/ManagerTest.php index 1f18a25115f..737a41425e1 100644 --- a/tests/lib/DirectEditing/ManagerTest.php +++ b/tests/lib/DirectEditing/ManagerTest.php @@ -153,9 +153,9 @@ class ManagerTest extends TestCase { ->method('generate') ->willReturn($expectedToken); $this->userFolder - ->method('get') + ->method('nodeExists') ->with('/File.txt') - ->willThrowException(new NotFoundException()); + ->willReturn(false); $this->userFolder->expects($this->once()) ->method('newFile') ->willReturn($file); @@ -173,9 +173,9 @@ class ManagerTest extends TestCase { ->method('generate') ->willReturn($expectedToken); $this->userFolder - ->method('get') + ->method('nodeExists') ->with('/File.txt') - ->willThrowException(new NotFoundException()); + ->willReturn(false); $this->userFolder->expects($this->once()) ->method('newFile') ->willReturn($file); @@ -188,6 +188,10 @@ class ManagerTest extends TestCase { public function testCreateFileAlreadyExists() { $this->expectException(\RuntimeException::class); + $this->userFolder + ->method('nodeExists') + ->with('/File.txt') + ->willReturn(true); $this->manager->create('/File.txt', 'testeditor', 'createEmpty'); } |