Skip to content
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

Closed

Conversation

stagnation
Copy link
Contributor

@stagnation stagnation commented Feb 16, 2024

Two refactorings to prepare for resolving, parsing and building paths with drive letters on Windows.

Copy link
Member

@EdSchouten EdSchouten left a 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/component_walker.go Outdated Show resolved Hide resolved
pkg/filesystem/path/parser.go Outdated Show resolved Hide resolved
pkg/filesystem/path/parser.go Outdated Show resolved Hide resolved
pkg/filesystem/path/parser.go Outdated Show resolved Hide resolved
pkg/filesystem/path/parser.go Outdated Show resolved Hide resolved
pkg/filesystem/path/resolve.go Outdated Show resolved Hide resolved
if err != nil {
return err
}
rs.stack = append(rs.stack, path)
if remainder != nil {
Copy link
Member

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.

Copy link
Contributor Author

@stagnation stagnation Feb 20, 2024

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

@stagnation stagnation force-pushed the feature/refactor-path-resolve branch 2 times, most recently from 2eab22b to 05d0bb5 Compare February 20, 2024 13:21
Copy link
Member

@EdSchouten EdSchouten left a 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.

pkg/filesystem/path/resolve.go Outdated Show resolved Hide resolved
pkg/filesystem/path/resolve.go Outdated Show resolved Hide resolved
@@ -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")
Copy link
Member

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.

Copy link
Contributor Author

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 :)

pkg/filesystem/path/unix_parser.go Outdated Show resolved Hide resolved
@stagnation stagnation force-pushed the feature/refactor-path-resolve branch from fb92218 to ad3820a Compare March 7, 2024 13:56
Comment on lines 18 to 19
// OnRelative() may be called at most once, and both must never be
// called on the same path. Resolve() will always call into one of
Copy link
Member

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?

Copy link
Contributor Author

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/scope_walker.go Outdated Show resolved Hide resolved
}

// NewUNIXParser creates a Parser for Unix paths that can be used in Resolve.
func NewUNIXParser(path string) (Parser, error) {
Copy link
Member

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 methods
  • unixRelativeParser and its methods


// 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.
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds a lot better!

@stagnation stagnation force-pushed the feature/refactor-path-resolve branch from ad3820a to bab2e10 Compare March 7, 2024 15:43
@EdSchouten
Copy link
Member

LGTM! Will merge after you've addressed that gofmt issue.

@EdSchouten EdSchouten closed this in 4d0d7a3 Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants