-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get success when try to create a folder that already exists #44507
Get success when try to create a folder that already exists #44507
Conversation
3a21135
to
3817962
Compare
The PHP function mkdir return false when the directory already exists: https://www.php.net/manual/en/function.mkdir.php#refsect1-function.mkdir-returnvalues If the directory that we is trying to create already exists, would be good to return success and consider that the folder exists to prevent fatal error because the scenario about existing folder is not covered now. Signed-off-by: Vitor Mattos <vitor@php.rio>
3817962
to
177dde6
Compare
@@ -159,7 +159,9 @@ public function newFolder($path) { | |||
$nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); | |||
$this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]); | |||
if (!$this->view->mkdir($fullPath)) { | |||
throw new NotPermittedException('Could not create folder "' . $fullPath . '"'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not the opposite?
Check with is_dir
first, try to mkdir
after it needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the most simple way to don't generate big impacts at the code. The original code generates an error, I only wrapped the error with a condition to prevent generate the error when the directory exists.
Thinking more, If we check if is a directory before make the directory, will be in the most cases, a more step. I think that is most fast only check if the path is a directory after the command mkdir return false. Create the directory is the main objective, if works fine, we don't do nothing, we only need to check if is a dir to prevent to generate a wrong error (reading, wrong error sounds strange 😂).
Should avoid things like these, where the folder indeed exists ond disk (race condtion?):
|
Was exactly this the error that I fixed. |
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! |
Closing my PR after then my solution was implemented at PR: #45413 |
The PHP function mkdir return false when the directory already exists:
https://www.php.net/manual/en/function.mkdir.php#refsect1-function.mkdir-returnvalues
If the directory that we is trying to create already exists, would be good to return success and consider that the folder exists to prevent fatal error because the scenario about existing folder is not covered now.
How to reproduce this:
Try to create a folder that already exists.
Checklist