-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix create SimpleFile with empty content #21386
Conversation
After that change #19493 where you have to provide content to method `newFile` is a bug with empty `''` content. Php function `file_put_contents` will returns the numbers of bytes that written to the file, or `FALSE` on failure https://www.php.net/manual/en/function.file-put-contents.php So for empty `''` content it will return `0` which is `true` for this statement: ``` if (!$result) { throw new NotPermittedException('Could not create path'); } ``` From now empty content will not throws an exception.
Thanks 👍 That looks danger. If the underlying storage is an object store for example the result might be true instead of 0. The storage adapter "local" should be changed to follow the interface and return a boolean always. server/lib/private/Files/Storage/Local.php Lines 272 to 274 in 6b26744
|
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.
Looks good.
Would you mind also adding a test case?
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.
Ah woops. Yes @kesselb is right. Please modify the local storage to behave properly.
The same "problem" is here: server/lib/private/Files/Storage/Common.php Lines 205 to 211 in 6b26744
Implementation is not Ok with the interface: server/lib/public/Files/Storage.php Lines 229 to 237 in 6b26744
I can fix it but is it Ok? Origin file_put_contents return how much bytes were written and maybe someone wants to compare it with data sent to the method?
What about test case, I can write it too but there aren't any test cases with content so should I write them too? |
Another fix went into master already: #22237 |
After that change #19493 where
you have to provide content to method
newFile
is a bug with empty''
content.
Php function
file_put_contents
will returns the numbers of bytes thatwritten to the file, or
FALSE
on failurehttps://www.php.net/manual/en/function.file-put-contents.php
So for empty
''
content it will return0
which istrue
for thisstatement:
From now empty content will not throws an exception.