should_replace_duplicate

Function should_replace_duplicate 

Source
pub fn should_replace_duplicate(
    existing: &LockedResource,
    new_entry: &LockedResource,
) -> bool
Expand description

Determines if a new lockfile entry should replace an existing duplicate entry.

Uses a deterministic merge strategy to ensure consistent lockfile generation regardless of processing order (e.g., HashMap iteration order).

§Merge Priority Rules (highest to lowest)

  1. Manifest dependencies win - Direct manifest dependencies (with manifest_alias) always take precedence over transitive dependencies
  2. install=true wins - Dependencies that create files (install=true) are preferred over content-only dependencies (install=false)
  3. First wins - If both have equal priority, keep the existing entry

This ensures that the lockfile is deterministic even when:

  • Dependencies are processed in different orders
  • HashMap iteration order varies between runs
  • Multiple parents declare the same transitive dependency with different settings

§Arguments

  • existing - The current entry in the lockfile
  • new_entry - The new entry being added

§Returns

true if the new entry should replace the existing one, false otherwise