Merge pull request #15290 from nextcloud/fix/8635/mdkir-handling+no-create-to-delete

take return of mkdir into consideration; photocache to not create a folder for deletion
This commit is contained in:
John Molakvoæ 2019-04-30 09:25:45 +02:00 committed by GitHub
commit e727e01701
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View file

@ -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
}
}
}

View file

@ -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));