Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions lib/private/Preview/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,11 @@ private function getCachedPreview($files, $width, $height, $crop, $mimeType, $pr
* @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($fileId);
} catch (NotFoundException $e) {
$folder = $this->appData->newFolder($fileId);
try{
return $this->appData->newFolder((string)$file->getId());
Comment on lines -585 to +586
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment at the top of the method already explains why you can't always call newFolder().

Copy link
Contributor Author

@umgfoin umgfoin May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's safe to call newFolder() even if the folder exists.

I think you just need to add NotPermittedException to the exceptions that are caught.

Tried this, too, but with unsatisfying results on a first attempt.
As I don't have resources to dig deeper, right now, I decided to choose the above robust approach - performance impact should be comparable, for scope of Generator, logs are clean during preview-recreation after occ preview:clean
Feel free to modify this PR, but I recommend to observe the preview-creation process thoroughly during testing with different storage types and concurrent access - there seem to be a few pitfalls.

} catch (NotPermittedException $e) {
throw new NotFoundException('Creation or access of preview directory not permitted!');
}

return $folder;
}

/**
Expand Down
Loading