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

Fix Directory.glob on directories with a sub path #6904

Conversation

helderco
Copy link
Contributor

Fixes #6903

@helderco helderco requested review from jedevc and TomChv March 19, 2024 12:47
core/directory.go Show resolved Hide resolved
@@ -295,14 +293,14 @@ func (dir *Directory) Glob(ctx context.Context, src string, pattern string) ([]s
}
// empty directory, i.e. llb.Scratch()
if ref == nil {
if clean := path.Clean(src); clean == "." || clean == "/" {
if clean := path.Clean(dir.Dir); clean == "." || clean == "/" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.Entries uses the src = path.Join(dir.Dir, src) here, but this branch comes from the solve from dir.LLB which doesn't factor src.

I tried triggering the error after this "if" in a test but couldn't because I'm not entirely sure when ref is nil without an error.

If ref == nil really only happens in dag.directory(), I feel like just doing this here:

if ref == nil {
	return []string{}, nil
}

\cc @jedevc

Copy link
Member

Choose a reason for hiding this comment

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

SGTM - the only caller of Glob is in core/schema/directory.go, which only passes ., so every src directory is guaranteed to exist - so we shouldn't end up in a scenario where we hit the edge case.

@helderco helderco added this to the v0.10.3 milestone Mar 19, 2024
@jedevc
Copy link
Member

jedevc commented Mar 25, 2024

Can this be merged?

Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
@helderco helderco force-pushed the helder/oss-174-directoryglob-doesnt-work-when-parent-directory-isnt branch from 7be8608 to 3de2f18 Compare March 25, 2024 15:39
@helderco
Copy link
Contributor Author

Yep, just rebased. Waiting for checks.

@helderco helderco merged commit 7618055 into dagger:main Mar 25, 2024
43 checks passed
@helderco helderco deleted the helder/oss-174-directoryglob-doesnt-work-when-parent-directory-isnt branch March 25, 2024 16:07
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.

🐞 Directory.glob doesn’t work when parent directory isn’t "."
2 participants