Skip to content

chore: clean up module path handling from local - #6086

Merged
jedevc merged 3 commits into
dagger:mainfrom
jedevc:clean-up-local-module-resolution
Nov 14, 2023
Merged

jedevc merged 3 commits into
dagger:mainfrom
jedevc:clean-up-local-module-resolution

Conversation

@jedevc

@jedevc jedevc commented Nov 7, 2023

Copy link
Copy Markdown
Contributor

This patch detects some additional edge cases when loading modules, notably:

  • Fail if the server tries to load a module where the config is not under the root - this is still also checked client-side for the main module. However, by adding checks server-side, we also get this for dependencies as well.

Additionally, a few small nitpicks:

  • Use path/filepath instead of path.

    path/filepath uses OS-depedendant separators, which, while we're not using this, highlights that these are files.

  • Use filepath utilities wherever possible (e.g. use filepath.Rel instead of strings.TrimPrefix).

  • Check if a path is a parent to the current directory - strings.HasPrefix(target, "..") wasn't right, since a normal filename can begin with ...

@jedevc
jedevc force-pushed the clean-up-local-module-resolution branch from 3a31631 to ead9476 Compare November 7, 2023 16:00
Comment thread core/module.go Outdated
Comment on lines 245 to 256

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is actually the main "change" of this PR.

It ensures that a dependency "../foo" can't be loaded if the root is ".". Previously, this would silently succeed, and maybe actually try and load "./foo" instead.

However, we should explicitly error out.

@sipsma sipsma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit picks but overall LGTM, also very much worth a look from @vito since daggerverse calls some of this code directly too

Comment thread core/integration/module_test.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: any assertion on actual error (even just checking for a string) would be highly preferable so we have less chance of ending up in a situation where the test starts failing in the future but for a different reason and then we silently lose coverage

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to do this 🎉

Also bumped some things to handle the bad-self-dir where we should perform the filepath.Rel checks on absolute paths there so we don't get the weird Rel errors, and instead get our custom errors.

Comment thread core/module.go Resolved
@sipsma
sipsma requested a review from vito November 13, 2023 21:46
This patch detects some additional edge cases when loading modules,
notably:

- Fail if the server tries to load a module where the config is not
  under the root - this is still also checked client-side for the main
  module. However, by adding checks server-side, we also get this for
  dependencies as well.

Additionally, a few small nitpicks:

- Use `path/filepath` instead of `path`.

  `path/filepath` uses OS-depedendant separators, which, while we're not
  using this, highlights that these are files.

- Use filepath utilities wherever possible (e.g. use `filepath.Rel`
  instead of `strings.TrimPrefix`).

- Check if a path is a parent to the current directory -
  `strings.HasPrefix(target, "..")` wasn't right, since a normal
  filename *can* begin with `..`.

Signed-off-by: Justin Chadwell <[email protected]>
@jedevc
jedevc force-pushed the clean-up-local-module-resolution branch from ead9476 to 216abfd Compare November 14, 2023 12:34

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

@jedevc
jedevc merged commit f737550 into dagger:main Nov 14, 2023
@jedevc
jedevc deleted the clean-up-local-module-resolution branch November 14, 2023 15:12
schlapzz pushed a commit to schlapzz/dagger that referenced this pull request Nov 24, 2023
schlapzz pushed a commit to schlapzz/dagger that referenced this pull request Nov 24, 2023
schlapzz pushed a commit to schlapzz/dagger that referenced this pull request Nov 24, 2023
schlapzz pushed a commit to schlapzz/dagger that referenced this pull request Nov 24, 2023
schlapzz pushed a commit to schlapzz/dagger that referenced this pull request Nov 24, 2023
schlapzz pushed a commit to schlapzz/dagger that referenced this pull request Nov 24, 2023
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.

3 participants