]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix preview generator trying to recreate an existing folder 32323/head
authorRichard Steinmetz <richard@steinmetz.cloud>
Tue, 10 May 2022 11:37:30 +0000 (13:37 +0200)
committerRichard Steinmetz <richard@steinmetz.cloud>
Tue, 10 May 2022 11:37:30 +0000 (13:37 +0200)
Backport of #32315

Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
lib/private/Preview/Generator.php

index 6e1e0997a68f389a264776c31a3d2d92a0a5af82..4c15dd6a34fcec2a34b74ff93f32eadfa9fe4680 100644 (file)
@@ -31,6 +31,7 @@ namespace OC\Preview;
 
 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 @@ class Generator {
         *
         * @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;