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 bug where dev repo urls ending with a "/" would result in opam monorepo pull placing package source code directly inside the duniverse directory instead of in a subdirectory of the duniverse directory #359

Merged

Conversation

gridbugs
Copy link
Collaborator

No description provided.

@gridbugs gridbugs force-pushed the fix-trailing-slash-in-dev-repo-path-bug branch from 1fe18f0 to ab08f0a Compare November 28, 2022 15:44
Copy link
Member

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Choose a reason for hiding this comment

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

Good catch! It makes a lot of sense to make sure opam-monorepo pull doesn't write all over the users disk. I like that the tests also check for directory traversal out of the duniverse directory.

I've added some comments where I think things could be clearer, but I think the approach is good.

lib/dev_repo.mli Show resolved Hide resolved
Fpath.(is_prefix (normalize duniverse_dir) (normalize output_dir))
&& not (String.equal dir "")
then
let url = Url.to_opam_url url in
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this part should be split into it's own function, since long if-blocks followed by rather large else blocks are hard to read.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I split out the logic for deleting version control info and vendor dirs into its own function

test/lib/test_dev_repo.ml Show resolved Hide resolved
test/lib/test_duniverse.ml Show resolved Hide resolved
lib/dev_repo.ml Outdated Show resolved Hide resolved
lib/pull.ml Outdated Show resolved Hide resolved
@gridbugs gridbugs force-pushed the fix-trailing-slash-in-dev-repo-path-bug branch from ab08f0a to 0e0c590 Compare November 30, 2022 13:39
@gridbugs
Copy link
Collaborator Author

I've updated the code based on feedback but I haven't written any more tests yet. Will do tomorrow.

@gridbugs gridbugs force-pushed the fix-trailing-slash-in-dev-repo-path-bug branch from 0e0c590 to d217190 Compare December 1, 2022 02:36
@gridbugs
Copy link
Collaborator Author

gridbugs commented Dec 1, 2022

Added tests for cases where dev_repos fail to parse into names. I also hit a bug where String.drop_suffix was returning its argument unchanged when the suffix and the string were equal which I've fixed and added tests that it behaves as expected.

Copy link
Member

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Choose a reason for hiding this comment

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

This looks solid. I've found a few small typos on the way and also some musing about the surprising (existing) behavior of drop_suffix which is puzzling but I'm ok merging it like this.

Thanks for the work :)

lib/pull.ml Outdated Show resolved Hide resolved
stdext/string.ml Outdated Show resolved Hide resolved
test/bin/pull-invalid-path.t/run.t Outdated Show resolved Hide resolved
test/lib/test_dev_repo.ml Show resolved Hide resolved
test/lib/test_stdext.ml Outdated Show resolved Hide resolved
Previously these would be given a dev repo name of "" in the lockfile.
This would result in `opam monorepo pull` checking out package source
code directly inside the "duniverse" directory instead of in a
subdirectory.

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
Previously, certain adversarial dev repo names (e.g. "", "..") would
cause `opam monorepo pull` to create and delete files outside the
duniverse directory, or to place package source code directly inside the
duniverse directory instead of a subdirectory. This change adds a check
which prevents code being pulled into directories which are not
descendants of the duniverse directory.

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
@gridbugs gridbugs force-pushed the fix-trailing-slash-in-dev-repo-path-bug branch from 40547af to 64b718f Compare December 2, 2022 04:12
@Leonidas-from-XIV
Copy link
Member

LGTM! :)

@gridbugs gridbugs merged commit d159387 into tarides:main Dec 6, 2022
Leonidas-from-XIV added a commit to Leonidas-from-XIV/opam-repository that referenced this pull request Dec 21, 2022
CHANGES:

### Changed

- Treat packages with no build commands as if they can be built with dune (tarides/opam-monorepo#355,
  @gridbugs)

### Fixed

- Fix resolving refs of locally pinned repositories (tarides/opam-monorepo#326, tarides/opam-monorepo#332, @hannesm,
  @Leonidas-from-XIV)
- Read the `compiler` flag from OPAM metadata thus classifying more packages
  correctly as base packages (tarides/opam-monorepo#328, @Leonidas-from-XIV)
- Fix bug where dev repo urls ending with a "/" would result in
  `opam monorepo pull` placing package source code directly inside the duniverse
  directory instead of in a subdirectory of the duniverse directory (tarides/opam-monorepo#359,
  @gridbugs)
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.

None yet

2 participants