From 3c78116cf8b6b23c74f3270162471f10eb4f939e Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 29 Apr 2019 16:15:07 +0200 Subject: [PATCH] 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 eed11f1e93..8632fd45f2 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 + } } }