-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
FileSystem::copy() with $override = false can still override (overwrite) the target file #12937
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
Comments
@borekb You sure mean that part of code in Filesystem I agree that setting $override to false should mean, that the existing target file cannot be overridden.
|
Yes, that line, and as you've correctly pointed out there are actually three states. As a quick fix, I'd suggest updating the docs to make it very clear that |
What do you think of changing: Whether to override an existing file or not to Whether to force overwriting of an existing file or not ? |
It's better but I would probably still need to look at the source code to find out what the method actually does. I'm trying to come up with a good method description but it's kind of hard as this method is really a bit overloaded. Something like this maybe?
|
That's good. We shouldn't duplicate in comments what's already in the code. |
It my eyes, a state where this method had no comments and the third parameter was called Ultimately, I think the problem is a design one where the method should not do any time comparisons in the first place but if it does already and it's hard to change it because of possible BCs, then I think doc comments are actually very important and it should be clear from the what the behavior is. (BTW this is not an academic discussion, it cause us trouble because we misunderstood what the |
Can you send a PR updating the phpdoc ? |
So is the method description suggested in #12937 (comment) OK? If so, I'll open a PR. |
Hey, I think override must be boolean, overrides or not, but never depending on the last modification date... |
For what is worth, PHP's copy() function always overrides: |
This PR was squashed before being merged into the 2.3 branch (closes #18195). Discussion ---------- Improved the PHPdoc of FileSystem::copy() | Q | A | ------------- | --- | Branch | 2.3+ | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #12937 | License | MIT | Doc PR | - Commits ------- 9ad67ca Improved the PHPdoc of FileSystem::copy()
The API of FileSystem::copy() is unintuitive and its docs are probably flawed. It says:
But that's not true, even if
$override
is false the target might be overwritten if it's older than origin. Generally, I would expectnot to overwrite my $target but it does. Either the docs should make this very clear or the behavior should ideally be changed but that would probably mean a breaking change. Anyway, if #10547 gets a go ahead I think that the time comparison "magic" should be removed or at least hidden behind some appropriately named parameter.
The text was updated successfully, but these errors were encountered: