Fixes to path handling on Windows#2568
Merged
dantleech merged 1 commit intophpactor:masterfrom Feb 27, 2024
Merged
Conversation
Paths don't start with '/', so use helpers for absolute/relative path, and may use both '/' and '\', so canonicalize before comparing them. This resolves 26 test failures on Windows.
dantleech
reviewed
Feb 27, 2024
| $path = '/'.$path; | ||
| if (!Path::isAbsolute($path)) { | ||
| // Not sure if this makes sense… Maybe it should just throw? | ||
| $path = Path::makeAbsolute($path, '/'); |
Collaborator
There was a problem hiding this comment.
i think the idea is that this is always absolute, so fromParts(['home','daniel',])
Contributor
Author
There was a problem hiding this comment.
To elaborate, there are two things that confuse me:
- Where does data in this format come from? I'm not aware of any filesystem APIs that return paths like that, and I've never seen anyone use that format in their configuration. I also couldn't find what in your code generates them. I'm like 70% sure that this code path is unused apart from tests.
- How is this supposed to work with Windows paths, where absolute paths must have a drive letter (e.g. "C:") in addition to the list of path segments? The way I made it work here, this function actually returns a drive-relative path (e.g. "\Users\daniel"), not an absolute one ("C:\Users\daniel"), and the drive letter will be resolved against the current working directory when trying to read from the path. This will probably often work, but it sometimes won't.
Collaborator
There was a problem hiding this comment.
it's used here:
https://github.com/phpactor/phpactor/blob/master/lib/Filesystem/Adapter/Simple/SimpleFilesystem.php
i guess it won't work for Windows... but feel free to throw an exception here, if the tests pass then it's all good.
Contributor
Author
There was a problem hiding this comment.
Hmm, just this one method?
public function createPath(string $path): FilePath
{
if (Path::isRelative($path)) {
return FilePath::fromParts([$this->path->path(), $path]);
}
...
}If $this->path->path() is an absolute path, and it looks like it should be, then that will be fine.
Collaborator
|
nice, thanks |
This was referenced Feb 27, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Paths don't start with '/', so use helpers for absolute/relative path, and may use both '/' and '\', so canonicalize before comparing them.
This resolves 26 test failures on Windows.