Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Filesystem] Add a cross-platform readlink method#17498
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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 would have defaulted totrue here. Or even better, why not create 2 methods?
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.
Or just keep realpath, which is very useful. I'm not sure readlink is that useful anyway.
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.
When you say realpath, what do you mean :) ? With final target to true ?
We are using both the "not final" and the "final" cases in Puli, I think two methods is a good idea indeed. How should we name them though? If we choose realpath/readlink, which convention do we choose? I would prefer the Unix one personnally (realpath = final, readlink = not final).
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.
Indeed, the Linux convention seems the best one.
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 did the change, but I think the name "realpath" is misleading. The PHP realpath do more things than resolving links (it also canonicalizes and normalizes the path:http://php.net/manual/fr/function.realpath.php). I'm not sure what happens in our case on Windows / Unix and if the behavior is really the same everywhere. Perhaps should we find a better name.
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.
What do you think ofreadLink for "not final" andresolveLink for "final"?
tgalopin commentedJan 26, 2016
Any opinion on the methods names here? |
tgalopin commentedJan 29, 2016
I rebased this on master. What do you think if this feature? |
fabpot commentedMar 4, 2016
I would use the method names from the Linux behavior. |
| thrownewIOException(sprintf('The link %s does not exist and cannot be read.',$path)); | ||
| } | ||
| if (!is_link($path)) { |
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 shouldn't this method work on regular files/dirs?
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'm not sure what you mean, but the support of non-links paths was something I found useful. This can be changed, I'm not sure what's the excepted behavior.
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.
PHP'sreadlink() function will emit a warning if the given path is no link. I think we should throw anInvalidArgumentException then.
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.
That seems appropriate indeed.
0b94a11 tof90548aComparetgalopin commentedMar 12, 2016
I did the changes. |
xabbuh commentedMar 13, 2016
looks like you need to fix the tests Status: Needs Work |
tgalopin commentedMar 13, 2016
I fixed the tests |
af2ad79 to583fdf1Comparetgalopin commentedApr 15, 2016
I think this is ready, targeting 3.1. Any review? |
| if (!$this->exists($path)) { | ||
| thrownewIOException(sprintf('The link %s does not exist and cannot be read.',$path)); | ||
| } | ||
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 this limitation ?
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'm not sure what behavior we should have. The native behavior is to return false, but that seems inapropriate to me as we should return a string. What would you expect?
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.
Ok I understood, OK for exception here for me
tgalopin commentedApr 19, 2016
By canonicalized, do you mean absolute or also fully resolved link? |
nicolas-grekas commentedApr 19, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Both, ie what realpath does (on PHP/Linux) |
faa689c to259b4ddComparefabpot commentedJun 21, 2016
@tgalopin Any news on this PR? Is it worth finishing it? |
tgalopin commentedJun 21, 2016
@fabpot I think it is, I'll work on it. |
tgalopin commentedJul 29, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
After some research, I propose the following behavior (same for every platform), following the way the Signature: By default (
With canonicalization (
Is everyone OK with this behavior? If it's ok for everyone, I'll start working on it. |
nicolas-grekas commentedJul 29, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Ok for me with this updated version (no exceptions but return null instead) |
8efe4a5 toe79b1a5Comparetgalopin commentedJul 29, 2016
I applied this behavior and tests are green, I think this is ready for review. |
fa3b7fd to7ed04a4Comparenicolas-grekas commentedJul 30, 2016
👍 |
fabpot commentedJul 30, 2016
Thank you@tgalopin. |
…lopin)This PR was merged into the 3.2-dev branch.Discussion----------[Filesystem] Add a cross-platform readlink method| Q | A| ------------- | ---| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -`readlink()` and `realpath()` have a completely different behavior under Windows and Unix:- `realpath()` resolves recursively the children links of a link until a final target is found on Unix and resolves only the next link on Windows ;- `readlink()` resolves recursively the children links of a link until a final target is found on Windows and resolves only the next link on Unix ;I propose to solve this by implementing a helper method in the Filesystem component that would behave always the same way under all platforms.Commits-------c36507e [Filesystem] Add a cross-platform readlink/realpath methods for nested links
…(tgalopin)This PR was merged into the master branch.Discussion----------[Filesystem] Add documentation for the readlink methodFollowing the merge ofsymfony/symfony#17498, this PR introduces documentation for the new methd `readlink`.Commits-------3572a3d [Filesystem] Add documentation for the readlink method
readlink()andrealpath()have a completely different behavior under Windows and Unix:realpath()resolves recursively the children links of a link until a final target is found on Unix and resolves only the next link on Windows ;readlink()resolves recursively the children links of a link until a final target is found on Windows and resolves only the next link on Unix ;I propose to solve this by implementing a helper method in the Filesystem component that would behave always the same way under all platforms.