fn remove_orphaned_bins(
    ws: &Workspace<'_>,
    tracker: &mut InstallTracker,
    duplicates: &BTreeMap<String, Option<PackageId>>,
    pkg: &Package,
    dst: &Path,
) -> CargoResult<()> {
    let filter = ops::CompileFilter::new_all_targets();
    let all_self_names = exe_names(pkg, &filter);
    let mut to_remove: HashMap<PackageId, BTreeSet<String>> = HashMap::new();
    // For each package that we stomped on.
    for other_pkg in duplicates.values().flatten() {
        // Only for packages with the same name.
        if other_pkg.name() == pkg.name() {
            // Check what the old package had installed.
            if let Some(installed) = tracker.installed_bins(*other_pkg) {
                // If the old install has any names that no longer exist,
                // add them to the list to remove.
                for installed_name in installed {
                    if !all_self_names.contains(installed_name.as_str()) {
                        to_remove
                            .entry(*other_pkg)
                            .or_default()
                            .insert(installed_name.clone());
                    }
                }
            }
        }
    }

    for (old_pkg, bins) in to_remove {
        tracker.remove(old_pkg, &bins);
        for bin in bins {
            let full_path = dst.join(bin);
            if full_path.exists() {
                ws.config().shell().status(
                    "Removing",
                    format!(
                        "executable `{}` from previous version {}",
                        full_path.display(),
                        old_pkg
                    ),
                )?;
                paths::remove_file(&full_path)
                    .with_context(|| format!("failed to remove {:?}", full_path))?;
            }
        }
    }
    Ok(())
}
/// Removes executables that are no longer part of a package that was
/// previously installed.
Removes executables that are no longer part of a package that was
previously installed.
Removes executables that are no longer part of a package that was previously installed .
fn remove_orphaned_bins(
    ws: &Workspace<'_>,
    tracker: &mut InstallTracker,
    duplicates: &BTreeMap<String, Option<PackageId>>,
    pkg: &Package,
    dst: &Path,
) -> CargoResult<()> {
    let filter = ops::CompileFilter::new_all_targets();
    let all_self_names = exe_names(pkg, &filter);
    let mut to_remove: HashMap<PackageId, BTreeSet<String>> = HashMap::new();
    // For each package that we stomped on.
    for other_pkg in duplicates.values().flatten() {
        // Only for packages with the same name.
        if other_pkg.name() == pkg.name() {
            // Check what the old package had installed.
            if let Some(installed) = tracker.installed_bins(*other_pkg) {
                // If the old install has any names that no longer exist,
                // add them to the list to remove.
                for installed_name in installed {
                    if !all_self_names.contains(installed_name.as_str()) {
                        to_remove
                            .entry(*other_pkg)
                            .or_default()
                            .insert(installed_name.clone());
                    }
                }
            }
        }
    }
    for (old_pkg, bins) in to_remove {
        tracker.remove(old_pkg, &bins);
        for bin in bins {
            let full_path = dst.join(bin);
            if full_path.exists() {
                ws.config().shell().status(
                    "Removing",
                    format!(
                        "executable `{}` from previous version {}",
                        full_path.display(),
                        old_pkg
                    ),
                )?;
                paths::remove_file(&full_path)
                    .with_context(|| format!("failed to remove {:?}", full_path))?;
            }
        }
    }
    Ok(())
}
fn remove_orphaned_bins ( ws : & Workspace < ' _ > , tracker : & mut InstallTracker , duplicates : & BTreeMap < String , Option < PackageId > > , pkg : & Package , dst : & Path , ) -> CargoResult < ( ) > { let filter = ops :: CompileFilter :: new_all_targets ( ) ; let all_self_names = exe_names ( pkg , & filter ) ; let mut to_remove : HashMap < PackageId , BTreeSet < String > > = HashMap :: new ( ) ; // For each package that we stomped on. for other_pkg in duplicates . values ( ) . flatten ( ) { // Only for packages with the same name. if other_pkg . name ( ) == pkg . name ( ) { // Check what the old package had installed. if let Some ( installed ) = tracker . installed_bins ( * other_pkg ) { // If the old install has any names that no longer exist, // add them to the list to remove. for installed_name in installed { if ! all_self_names . contains ( installed_name . as_str ( ) ) { to_remove . entry ( * other_pkg ) . or_default ( ) . insert ( installed_name . clone ( ) ) ; } } } } } for ( old_pkg , bins ) in to_remove { tracker . remove ( old_pkg , & bins ) ; for bin in bins { let full_path = dst . join ( bin ) ; if full_path . exists ( ) { ws . config ( ) . shell ( ) . status ( " " , format ! ( " " full_path display ( ) old_pkg ) , ) ? ; paths :: remove_file ( & full_path ) . with_context ( | | format ! ( " " full_path ) ) ? ; } } } Ok ( ( ) ) }
Removes executables that are no longer part of a package that was
previously installed.
Removes executables that are no longer part of a package that was previously installed .
ws
&Workspace<'_>
tracker
&mut InstallTracker
duplicates
&BTreeMap<String, Option<PackageId>>
pkg
&Package
dst
&Path
ws
&Workspace<'_>
tracker
&mut InstallTracker
duplicates
&BTreeMap<String, Option<PackageId>>
pkg
&Package
dst
&Path