Skip to content

Commit 6da3fc6

Browse files
authored
Merge pull request #32323 from nextcloud/fix/noid/preview-duplicate-folder-creation-stable23
[stable23] Fix preview generator trying to recreate an existing folder
2 parents 9ff3b29 + 468ff90 commit 6da3fc6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/private/Preview/Generator.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
use OCP\Files\File;
3333
use OCP\Files\IAppData;
34+
use OCP\Files\InvalidPathException;
3435
use OCP\Files\NotFoundException;
3536
use OCP\Files\NotPermittedException;
3637
use OCP\Files\SimpleFS\ISimpleFile;
@@ -464,12 +465,19 @@ private function getCachedPreview(ISimpleFolder $previewFolder, $width, $height,
464465
*
465466
* @param File $file
466467
* @return ISimpleFolder
468+
*
469+
* @throws InvalidPathException
470+
* @throws NotFoundException
471+
* @throws NotPermittedException
467472
*/
468473
private function getPreviewFolder(File $file) {
474+
// Obtain file id outside of try catch block to prevent the creation of an existing folder
475+
$fileId = (string)$file->getId();
476+
469477
try {
470-
$folder = $this->appData->getFolder($file->getId());
478+
$folder = $this->appData->getFolder($fileId);
471479
} catch (NotFoundException $e) {
472-
$folder = $this->appData->newFolder($file->getId());
480+
$folder = $this->appData->newFolder($fileId);
473481
}
474482

475483
return $folder;

0 commit comments

Comments
 (0)