ktra icon indicating copy to clipboard operation
ktra copied to clipboard

Dependency listed incorrectly if it has aliased

Open cr0sh opened this issue 4 years ago • 0 comments

Hi @moriturus, thanks for open-sourcing this useful project. It works very smoothly(especially with Docker containers :D), but I believe there is a subtle bug:

When a package to be published has a dependency with package field, ktra places it into index wrongly.

Steps to reproduce:

  1. Create a dummy package(say foo)
[package]
name = "foo"
version = "0.1.0"
edition = "2018"


[dependencies]
hello-world = { version = "*", package = "hello" }
  1. Publish it
  2. Referring Cargo reference, the added index should have dependency with fields "name": "hello-world", "package": "hello", but two fields are interchanged. This causes confusing dependency resolution failure on cargo fetch(no matching package), although cargo search on ktra registry returns the exact package.

To resolve, Into<Dependency> impl of MetadataDependency should swap two fields.

https://github.com/moriturus/ktra/blob/8a14cd2a5b9edf6c7de8a56f0c72462716e2ddde/src/models.rs#L19-L34

(possibly fixing) change:

        Dependency {
            name: self
                .explicit_name_in_toml
                .clone()
                .unwrap_or_else(|| self.name.clone()),
            req: self.version_req,
            features: self.features,
            optional: self.optional,
            default_features: self.default_features,
            target: self.target,
            kind: self.kind,
            registry: self.registry,
            package: if self.explicit_name_in_toml.is_some() {
                Some(self.name)
            } else {
                None
            },
        }

Thanks in advance!

cr0sh avatar Oct 14 '21 08:10 cr0sh