From 0b883ab9d940650582e8ee02ada5bf13c2be7915 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 28 Feb 2018 15:40:01 +0100 Subject: [PATCH] Catch exception when the parent is deleted as well Signed-off-by: Joas Schilling --- apps/files/lib/Activity/Provider.php | 29 ++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/apps/files/lib/Activity/Provider.php b/apps/files/lib/Activity/Provider.php index 8c17f402fad..e868e1c464a 100644 --- a/apps/files/lib/Activity/Provider.php +++ b/apps/files/lib/Activity/Provider.php @@ -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 *