Skip to content

Conversation

@thaJeztah
Copy link
Collaborator

If both a "versioned" and "non-versioned" version of a dependency
exists in vendor.conf, the "longest" path should be cloned last,
otherwise the versioned dependency may be deleted when cloning its
non-versioned variant.

For example, with the following vendor.conf:

github.com/coreos/go-systemd/v22 v22.0.0
github.com/coreos/go-systemd     v17

Running vndr would;

  1. recursively delete "vendor/src/github.com/coreos/go-systemd/v22:
  2. start cloning "github.com/coreos/go-systemd/v22"
  3. recursively delete "vendor/src/github.com/coreos/go-systemd"
  4. start cloning "github.com/coreos/go-systemd"

This would lead to a conflicting situation; step 3. will remove
the dependency that was previously cloned (or in the process
of being cloned).

This patch sorts the dependencies by import-path, cloning the
shortest import paths first, which should prevent the race condition.

If both a "versioned" and "non-versioned" version of a dependency
exists in vendor.conf, the "longest" path should be cloned last,
otherwise the versioned dependency may be deleted when cloning its
non-versioned variant.

For example, with the following vendor.conf:

    github.com/coreos/go-systemd/v22 v22.0.0
    github.com/coreos/go-systemd     v17

Running vndr would;

1. recursively delete "vendor/src/github.com/coreos/go-systemd/v22:
2. start cloning "github.com/coreos/go-systemd/v22"
3. recursively delete "vendor/src/github.com/coreos/go-systemd"
4. start cloning "github.com/coreos/go-systemd"

This would lead to a conflicting situation; step 3. will remove
the dependency that was previously cloned (or in the process
of being cloned).

This patch sorts the dependencies by import-path, cloning the
shortest import paths first, which should prevent the race condition.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
func cloneAll(vd string, ds []depEntry) error {
// Sort dependencies so that longest import paths are handled last. This
// prevents, e.g. "github.com/foo/bar" from deleting "github.com/foo/bar/v3"
sort.Slice(ds, func(i, j int) bool {

Choose a reason for hiding this comment

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

Does sort.Strings not work here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are structs, not a plain string slice

@LK4D4
Copy link
Owner

LK4D4 commented May 6, 2020

Omg, sorry, folks - Gmail ate my github label and I missed. Will review today.

@LK4D4
Copy link
Owner

LK4D4 commented May 6, 2020

@thaJeztah Do you have time to try to write (or modify existing) unit-test?
Thanks!

@thaJeztah
Copy link
Collaborator Author

thaJeztah commented May 6, 2020 via email

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