-
Notifications
You must be signed in to change notification settings - Fork 96
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
Feature/refactor path resolve #190
Feature/refactor path resolve #190
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.
Great stuff!
pkg/filesystem/path/resolve.go
Outdated
if err != nil { | ||
return err | ||
} | ||
rs.stack = append(rs.stack, path) | ||
if remainder != nil { |
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.
Maybe we can require that Parser.ParseScope() always returns a RelativePath? That way this code can just push it on the stack unconditionally.
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.
Yeah, in the absence of an error there will always be a remainder. But the two nilable return vaules do not reflect this. As the code is written it is safe to drop the check, if that is desireable (I prefer the belt-and-suspenders).
Or I could refactor the ParseScope function to just return everything with the named output arguments,
and then the error being there is all that matters. How do you handle cases like this?
Something something sum-types
2eab22b
to
05d0bb5
Compare
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.
This is shaping up nicely. I think we can merge this soon.
@@ -16,74 +16,74 @@ func TestResolve(t *testing.T) { | |||
ctrl := gomock.NewController(t) | |||
|
|||
t.Run("NullByte", func(t *testing.T) { | |||
scopeWalker := mock.NewMockScopeWalker(ctrl) | |||
|
|||
_, err := path.NewUNIXParser("hello\x00world") |
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.
Technically speaking this test should be moved into unix_parser_test.go or something, but I have to say I don't care strongly.
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 can do that when we flesh out an alternative implementation :)
2b53980
to
fb92218
Compare
fb92218
to
ad3820a
Compare
pkg/filesystem/path/scope_walker.go
Outdated
// OnRelative() may be called at most once, and both must never be | ||
// called on the same path. Resolve() will always call into one of |
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 does "and both must never be called on the same path" mean? Isn't this redundant with what's stated before that?
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.
Yes it is redundant, I wanted to make it super clear but happy to remove it if it is clear enough :)
pkg/filesystem/path/unix_parser.go
Outdated
} | ||
|
||
// NewUNIXParser creates a Parser for Unix paths that can be used in Resolve. | ||
func NewUNIXParser(path string) (Parser, error) { |
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.
Could you maybe reorder the contents of this file to be more logical? For example:
- Utility functions at the top
unixParser
,*NewUNIXParser()
, and its methodsunixRelativeParser
and its methods
pkg/filesystem/path/parser.go
Outdated
|
||
// Parser is used by Resolve to parse paths in the resolution. | ||
// The Parser implementations will be used by value in several bookkeeping | ||
// structures, they must be implemented so they can safely be given as values. |
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 think "safely be given as values" is not a very clear way of phrasing it. I would recommend that we state something like this instead:
Implementations of ParseScope() should return a new copy of Parser and leave the current instance unmodified. It is permitted to call ParseScope() multiple times.
The same for RelativeParser.
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.
Sounds a lot better!
This prepares for platform specific paths.
ad3820a
to
bab2e10
Compare
LGTM! Will merge after you've addressed that gofmt issue. |
Two refactorings to prepare for resolving, parsing and building paths with drive letters on Windows.