Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

URL package not works #57

Closed
Rustin170506 opened this issue Dec 5, 2023 · 1 comment
Closed

URL package not works #57

Rustin170506 opened this issue Dec 5, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Rustin170506
Copy link
Owner

Rustin170506 commented Dec 5, 2023

Tested locally and it still doesn't work:
normal case without customized registry:

cargo info https://github.com/rust-lang/crates.io-index/clap
    Updating crates.io index
error: could not find `https://github.com/rust-lang/crates.io-index/clap` in registry `https://github.com/rust-lang/crates.io-index`

I printed the two URLs:

  1. spec URL: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("github.com")), port: None, path: "/rust-lang/crates.io-index/clap", query: None, fragment: None }
  2. source id URL: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("github.com")), port: None, path: "/rust-lang/crates.io-index", query: None, fragment: None }

As you can see the paths are different, so it won't match. I think this is a bug from cargo library: https://github.com/rust-lang/cargo/blob/9e9349d3f7a4ef687992b2f248bbe4fc5bfea09f/src/cargo/core/package_id_spec.rs#L146

    /// Tries to convert a valid `Url` to a `PackageIdSpec`.
    fn from_url(mut url: Url) -> CargoResult<PackageIdSpec> {
        if url.query().is_some() {
            bail!("cannot have a query string in a pkgid: {}", url)
        }
        let frag = url.fragment().map(|s| s.to_owned());
        url.set_fragment(None);
        let (name, version) = {
            let mut path = url
                .path_segments()
                .ok_or_else(|| anyhow::format_err!("pkgid urls must have a path: {}", url))?;
            let path_name = path.next_back().ok_or_else(|| {
                anyhow::format_err!(
                    "pkgid urls must have at least one path \
                     component: {}",
                    url
                )
            })?;
            match frag {
                Some(fragment) => match fragment.split_once([':', '@']) {
                    Some((name, part)) => {
                        let version = part.parse::<PartialVersion>()?;
                        (String::from(name), Some(version))
                    }
                    None => {
                        if fragment.chars().next().unwrap().is_alphabetic() {
                            (String::from(fragment.as_str()), None)
                        } else {
                            let version = fragment.parse::<PartialVersion>()?;
                            (String::from(path_name), Some(version))
                        }
                    }
                },
                None => (String::from(path_name), None),
            }
        };
        Ok(PackageIdSpec {
            name,
            version,
            url: Some(url),
        })
    }

We used the original URL as the package spec URL. In the matches function, we use it to match the source ID URL directly.

  /// Checks whether the given `PackageId` matches the `PackageIdSpec`.
    pub fn matches(&self, package_id: PackageId) -> bool {
        if self.name() != package_id.name().as_str() {
            return false;
        }

        if let Some(ref v) = self.version {
            if !v.matches(package_id.version()) {
                return false;
            }
        }

        if let Some(u) = &self.url {
            if u != package_id.source_id().url() {
                return false;
            }
        }

        true
    }
@Rustin170506
Copy link
Owner Author

This is a mistake. We should use https://github.com/rust-lang/crates.io-index#[email protected].

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant