Skip to content

Commit a87b9ed

Browse files
committed
do not create folder just to delete it afterwards
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent 7ec4687 commit a87b9ed

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

apps/dav/lib/CardDAV/PhotoCache.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,19 @@ private function getFile(ISimpleFolder $folder, $size) {
167167
}
168168

169169
/**
170-
* @param int $addressBookId
171-
* @param string $cardUri
172-
* @return ISimpleFolder
170+
* @throws NotFoundException
171+
* @throws NotPermittedException
173172
*/
174-
private function getFolder($addressBookId, $cardUri) {
173+
private function getFolder(int $addressBookId, string $cardUri, bool $createIfNotExists = true): ISimpleFolder {
175174
$hash = md5($addressBookId . ' ' . $cardUri);
176175
try {
177176
return $this->appData->getFolder($hash);
178177
} catch (NotFoundException $e) {
179-
return $this->appData->newFolder($hash);
178+
if($createIfNotExists) {
179+
return $this->appData->newFolder($hash);
180+
} else {
181+
throw $e;
182+
}
180183
}
181184
}
182185

@@ -271,9 +274,14 @@ private function getBinaryType(Binary $photo) {
271274
/**
272275
* @param int $addressBookId
273276
* @param string $cardUri
277+
* @throws NotPermittedException
274278
*/
275279
public function delete($addressBookId, $cardUri) {
276-
$folder = $this->getFolder($addressBookId, $cardUri);
277-
$folder->delete();
280+
try {
281+
$folder = $this->getFolder($addressBookId, $cardUri, false);
282+
$folder->delete();
283+
} catch (NotFoundException $e) {
284+
// that's OK, nothing to do
285+
}
278286
}
279287
}

0 commit comments

Comments
 (0)