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: don't allow the root package dependencies to be overwritten in the map #47

Merged
merged 1 commit into from
Aug 28, 2018
Merged

fix: don't allow the root package dependencies to be overwritten in the map #47

merged 1 commit into from
Aug 28, 2018

Conversation

schomatis
Copy link
Collaborator

fix: don't allow the root package dependencies to be overwritten in the map

The rewrite map is built recursively scanning the root package dependencies. If
two packages in the tree imported the same dependency with different hash the
last one to be processed would overwrite the first one.

Include a flag in `buildRewriteMapping` to signal when the root package
dependencies are being process and allow them to overwrite the map (adding an
overwrite flag in `addRewriteForDep`) but don't allow the inverse (transitive
dependencies overwriting direct ones).

This change has as a side effect that in a scenario where transitive
dependencies with different versions were overwriting each other that won't be
allowed now, changing in fact the rewrite map, but that would happen only in the
already problematic scenario of dependencies with mismatched versions.

Fixes #44.

Tested locally, it feels that it should have a test but I don't see any testing framework here (it would be nice to have it to easily create dependencies trees and test different scenarios, I'll open an issue about it.)

@schomatis schomatis self-assigned this Aug 21, 2018
@schomatis schomatis requested a review from Stebalien August 21, 2018 16:49
@schomatis schomatis added the bug label Aug 21, 2018
main.go Outdated
m[from] = to
} else if entryExists && m[from] != to {
VLog("trying to overwrite rewrite map entry %s poiting to %s with %s", from, m[from], to)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fix typo: "poiting".

…he map

The rewrite map is built recursively scanning the root package dependencies. If
two packages in the tree imported the same dependency with different hash the
last one to be processed would overwrite the first one.

Include a flag in `buildRewriteMapping` to signal when the root package
dependencies are being process and allow them to overwrite the map (adding an
overwrite flag in `addRewriteForDep`) but don't allow the inverse (transitive
dependencies overwriting direct ones).

This change has as a side effect that in a scenario where transitive
dependencies with different versions were overwriting each other that won't be
allowed now, changing in fact the rewrite map, but that would happen only in the
already problematic scenario of dependencies with mismatched versions.
Stebalien
Stebalien previously approved these changes Aug 27, 2018
@Stebalien Stebalien dismissed their stale review August 27, 2018 19:39

Actually, I'm not sure if this is the right fix.

@Stebalien
Copy link
Collaborator

So, this is a fix but, after thinking about this, I think the better fix is to change the traversal order to breadth first (and ban all overwriting). This catches the case where the root package overrides a dependency version but doesn't apply the same logic recursively.

How about:

  1. Adding rewrites for all dependencies of the current package in one loop.
  2. Recursing in a second loop.

@schomatis
Copy link
Collaborator Author

Do you mind merging this anyway while we discuss this other solution in the original issue? (The other gx-go link PR I'm working on already depends on this one, and although not optimal it's still a valid solution that would allow me to concentrate on that before revisiting this one.)

@Stebalien Stebalien merged commit 7de6d84 into whyrusleeping:master Aug 28, 2018
@Stebalien
Copy link
Collaborator

Fair enough. This fixes the immediate issue.

@schomatis schomatis deleted the fix/rewrite/root-deps branch August 28, 2018 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle rewrite map collisions
2 participants