Catch exception when the parent is deleted as well

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2018-02-28 15:40:01 +01:00
parent 5d8aaf9696
commit 8f8d7cf9d3
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with 27 additions and 2 deletions

View File

@ -395,8 +395,13 @@ class Provider implements IProvider {
$userFolder = $this->rootFolder->getUserFolder($this->activityManager->getCurrentUserId());
$files = $userFolder->getById($fileId);
if (empty($files)) {
// Deleted, try with parent
$file = $userFolder->get(dirname($path));
try {
// Deleted, try with parent
$file = $this->findExistingParent($userFolder, dirname($path));
} catch (NotFoundException $e) {
return null;
}
if (!$file instanceof Folder || !$file->isEncrypted()) {
return null;
}
@ -418,6 +423,26 @@ class Provider implements IProvider {
return $this->fileEncrypted[$fileId];
}
/**
* @param Folder $userFolder
* @param string $path
* @return Folder
* @throws NotFoundException
*/
protected function findExistingParent(Folder $userFolder, $path) {
if ($path === '/') {
throw new NotFoundException('Reached the root');
}
try {
$folder = $userFolder->get(dirname($path));
} catch (NotFoundException $e) {
return $this->findExistingParent($userFolder, dirname($path));
}
return $folder;
}
/**
* Check all parents until the user's root folder if one is encrypted
*