From 468ff9003182ec89078538309ea8674c68c51155 Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Tue, 10 May 2022 13:37:30 +0200 Subject: [PATCH] Fix preview generator trying to recreate an existing folder Backport of #32315 Signed-off-by: Richard Steinmetz --- lib/private/Preview/Generator.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index 6e1e0997a68f3..4c15dd6a34fce 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -31,6 +31,7 @@ use OCP\Files\File; use OCP\Files\IAppData; +use OCP\Files\InvalidPathException; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\Files\SimpleFS\ISimpleFile; @@ -464,12 +465,19 @@ private function getCachedPreview(ISimpleFolder $previewFolder, $width, $height, * * @param File $file * @return ISimpleFolder + * + * @throws InvalidPathException + * @throws NotFoundException + * @throws NotPermittedException */ private function getPreviewFolder(File $file) { + // Obtain file id outside of try catch block to prevent the creation of an existing folder + $fileId = (string)$file->getId(); + try { - $folder = $this->appData->getFolder($file->getId()); + $folder = $this->appData->getFolder($fileId); } catch (NotFoundException $e) { - $folder = $this->appData->newFolder($file->getId()); + $folder = $this->appData->newFolder($fileId); } return $folder;