Compare pkg ids based on their encoding.
authorDimitri Wegner <dimitri.wegner@here.com>
Tue, 29 May 2018 08:46:10 +0000 (10:46 +0200)
committerDimitri Wegner <dimitri.wegner@here.com>
Tue, 29 May 2018 08:46:10 +0000 (10:46 +0200)
This comparison is needed, since we want to figure out which packages
are duplicate in the lockfile. Package coming from different
registries will be different in the lockfile, but not local packages
with the same name and version but different path.

src/cargo/core/resolver/encode.rs
src/cargo/core/resolver/mod.rs
src/cargo/ops/lockfile.rs

index 36880c1b80b0704e8a40a92a86a99ed4f95f1954..6f9e3d39726c0ea95d5692e2f3faa07c0b022260 100644 (file)
@@ -414,7 +414,7 @@ fn encodable_resolve_node(id: &PackageId, resolve: &Resolve) -> EncodableDepende
     }
 }
 
-fn encodable_package_id(id: &PackageId) -> EncodablePackageId {
+pub fn encodable_package_id(id: &PackageId) -> EncodablePackageId {
     EncodablePackageId {
         name: id.name().to_string(),
         version: id.version().to_string(),
index e153daf088a71884f6873b924df485ce442dc109..f60560240447e75782d5bf87118951d345d2820b 100644 (file)
@@ -65,7 +65,7 @@ use self::context::{Activations, Context};
 use self::types::{ActivateError, ActivateResult, Candidate, ConflictReason, DepsFrame, GraphNode};
 use self::types::{RcVecIter, RegistryQueryer};
 
-pub use self::encode::{EncodableDependency, EncodablePackageId, EncodableResolve};
+pub use self::encode::{EncodableDependency, EncodablePackageId, EncodableResolve, encodable_package_id};
 pub use self::encode::{Metadata, WorkspaceResolve};
 pub use self::resolve::{Deps, DepsNotReplaced, Resolve};
 pub use self::types::Method;
index c3b648c2e25c62bfdb36dbc8ad14f1a3ee87690a..83bd906950325d66b14f357f32287db0444df1e8 100644 (file)
@@ -30,19 +30,20 @@ pub fn load_pkg_lockfile(ws: &Workspace) -> CargoResult<Option<Resolve>> {
     Ok(resolve)
 }
 
-fn duplicate_pkg_names(resolve: &Resolve) -> Vec<&'static str> {
+fn duplicate_pkgs(resolve: &Resolve) -> Vec<&'static str> {
     let mut unique_names = HashSet::new();
     let mut result = HashSet::new();
     for pkg_id in resolve.iter() {
-        if !unique_names.insert(pkg_id.name()) {
+        let mut encodable_pkd_id = resolver::encodable_package_id(pkg_id);
+        if !unique_names.insert(encodable_pkd_id) {
             result.insert(pkg_id.name().as_str());
         }
     }
     result.into_iter().collect()
 }
 
-fn check_duplicate_pkg_names(resolve: &Resolve) -> Result<(), Internal> {
-    let names = duplicate_pkg_names(resolve);
+fn check_duplicate_pkgs(resolve: &Resolve) -> Result<(), Internal> {
+    let names = duplicate_pkgs(resolve);
     if names.is_empty() {
         Ok(())
     } else {
@@ -63,7 +64,7 @@ pub fn write_pkg_lockfile(ws: &Workspace, resolve: &Resolve) -> CargoResult<()>
         Ok(s)
     });
 
-    check_duplicate_pkg_names(resolve).chain_err(|| format!("failed to generate lock file"))?;
+    check_duplicate_pkgs(resolve).chain_err(|| format!("failed to generate lock file"))?;
 
     let toml = toml::Value::try_from(WorkspaceResolve { ws, resolve }).unwrap();