From aa91b0ab3cf59fd2f6ae2b865fd62059b803b145 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 29 Apr 2019 16:12:01 +0200 Subject: [PATCH 1/2] take return of mkdir into account, throw exception on failure Signed-off-by: Arthur Schiwon --- lib/private/Files/Node/Folder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index a9b443ce52e..ebf67e47a21 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -158,7 +158,9 @@ class Folder extends Node implements \OCP\Files\Folder { $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); - $this->view->mkdir($fullPath); + if(!$this->view->mkdir($fullPath)) { + throw new NotPermittedException('Could not create folder'); + } $node = new Folder($this->root, $this->view, $fullPath); $this->root->emit('\OC\Files', 'postWrite', array($node)); $this->root->emit('\OC\Files', 'postCreate', array($node)); From 2f0055455d580e62bda696f7184a8cd9d935ce30 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 29 Apr 2019 16:15:07 +0200 Subject: [PATCH 2/2] do not create folder just to delete it afterwards Signed-off-by: Arthur Schiwon --- apps/dav/lib/CardDAV/PhotoCache.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/dav/lib/CardDAV/PhotoCache.php b/apps/dav/lib/CardDAV/PhotoCache.php index eed11f1e939..8632fd45f22 100644 --- a/apps/dav/lib/CardDAV/PhotoCache.php +++ b/apps/dav/lib/CardDAV/PhotoCache.php @@ -167,16 +167,19 @@ class PhotoCache { } /** - * @param int $addressBookId - * @param string $cardUri - * @return ISimpleFolder + * @throws NotFoundException + * @throws NotPermittedException */ - private function getFolder($addressBookId, $cardUri) { + private function getFolder(int $addressBookId, string $cardUri, bool $createIfNotExists = true): ISimpleFolder { $hash = md5($addressBookId . ' ' . $cardUri); try { return $this->appData->getFolder($hash); } catch (NotFoundException $e) { - return $this->appData->newFolder($hash); + if($createIfNotExists) { + return $this->appData->newFolder($hash); + } else { + throw $e; + } } } @@ -271,9 +274,14 @@ class PhotoCache { /** * @param int $addressBookId * @param string $cardUri + * @throws NotPermittedException */ public function delete($addressBookId, $cardUri) { - $folder = $this->getFolder($addressBookId, $cardUri); - $folder->delete(); + try { + $folder = $this->getFolder($addressBookId, $cardUri, false); + $folder->delete(); + } catch (NotFoundException $e) { + // that's OK, nothing to do + } } }