Fix: [Preview] Generator::getPreviewFolder fails to create preview folder in empty preview-structure#52946
Conversation
…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>
provokateurin
left a comment
There was a problem hiding this comment.
I think you just need to add NotPermittedException to the exceptions that are caught.
| // 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()); |
There was a problem hiding this comment.
The comment at the top of the method already explains why you can't always call newFolder().
There was a problem hiding this comment.
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.
|
Hello there, 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.) |
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:
server/lib/private/Files/SimpleFS/SimpleFolder.php
Line 75 in 249e33f
server/lib/private/Files/Node/Folder.php
Line 48 in 249e33f
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.
server/lib/private/Files/Node/Folder.php
Line 124 in 249e33f
Summary
TODO
Checklist