Skip to content

Fix: [Preview] Generator::getPreviewFolder fails to create preview folder in empty preview-structure#52946

Open
umgfoin wants to merge 1 commit intonextcloud:masterfrom
umgfoin:PR_UMGFOIN_fix_getPreviewFolder
Open

Fix: [Preview] Generator::getPreviewFolder fails to create preview folder in empty preview-structure#52946
umgfoin wants to merge 1 commit intonextcloud:masterfrom
umgfoin:PR_UMGFOIN_fix_getPreviewFolder

Conversation

@umgfoin
Copy link
Contributor

@umgfoin umgfoin commented May 19, 2025

Problem:
Generator fails to create preview-structure and files in an empty preview-structure (e.g. after occ preview:clean)

Cause:
Changed iFolder getFolder/ newFolder logic: getFolder(string path) throws unhandled NotPermittedException if an not existing path is supplied, which is regularly the case in an empty preview-dir structure. Anyway it's usage is obsolete here:

public function getFolder(string $name): ISimpleFolder {

public function getFullPath($path) {

Fix:
newFolder(string name) already implements the needed behaviour: It checks for an existing directory prior creating the new one and throws only if a folder with the new name does not already exist AND could not be created.
public function newFolder($path) {

  • Resolves: #

Summary

TODO

  • As most (dev-)installation come with already filled preview-folder structures, a test might be helpful to verify ability to create preview(-folder)s from scratch.

Checklist

…n empty preview-directory.

Reflect changed iFolder getFolder/ newFolder logic:
getFolder(string path) throws unhandled NotPermittedException if an not existing path is supplied, which is regularly the case in an empty preview-dir structure.. Anyway it's usage is obsolete here:

newFolder(string name) checks for an existing directory prior creating the new one. It throws only if a folder with the new name does not already exist AND could not be created. That's the needed behaviour here.
https://github.com/nextcloud/server/blob/249e33fcd67034b63aafdc7c3debd84982eb3cb3/lib/private/Files/Node/Folder.php#L124

Signed-off-by: umgfoin <umgfoin@users.noreply.github.com>
@umgfoin umgfoin requested a review from a team as a code owner May 19, 2025 08:13
@umgfoin umgfoin requested review from Altahrim and removed request for a team May 19, 2025 08:13
Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

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

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

Comment on lines -585 to +586
// 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());
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.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2025

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants