pub fn new(
        config: &'cfg Config,
        root: Filesystem,
        map: SourceConfigMap<'_>,
        krate: Option<&str>,
        source_id: SourceId,
        from_cwd: bool,
        vers: Option<&'a str>,
        opts: &'a ops::CompileOptions,
        force: bool,
        no_track: bool,
        needs_update_if_source_is_index: bool,
    ) -> CargoResult<Option<InstallablePackage<'cfg, 'a>>> {
        if let Some(name) = krate {
            if name == "." {
                bail!(
                    "To install the binaries for the package in current working \
                     directory use `cargo install --path .`. \
                     Use `cargo build` if you want to simply build the package."
                )
            }
        }

        let dst = root.join("bin").into_path_unlocked();
        let pkg = {
            let dep = {
                if let Some(krate) = krate {
                    let vers = if let Some(vers_flag) = vers {
                        Some(parse_semver_flag(vers_flag)?.to_string())
                    } else if source_id.is_registry() {
                        // Avoid pre-release versions from crate.io
                        // unless explicitly asked for
                        Some(String::from("*"))
                    } else {
                        None
                    };
                    Some(Dependency::parse(krate, vers.as_deref(), source_id)?)
                } else {
                    None
                }
            };

            if source_id.is_git() {
                let mut source = GitSource::new(source_id, config)?;
                select_pkg(
                    &mut source,
                    dep,
                    |git: &mut GitSource<'_>| git.read_packages(),
                    config,
                )?
            } else if source_id.is_path() {
                let mut src = path_source(source_id, config)?;
                if !src.path().is_dir() {
                    bail!(
                        "`{}` is not a directory. \
                     --path must point to a directory containing a Cargo.toml file.",
                        src.path().display()
                    )
                }
                if !src.path().join("Cargo.toml").exists() {
                    if from_cwd {
                        bail!(
                            "`{}` is not a crate root; specify a crate to \
                         install from crates.io, or use --path or --git to \
                         specify an alternate source",
                            src.path().display()
                        );
                    } else if src.path().join("cargo.toml").exists() {
                        bail!(
                            "`{}` does not contain a Cargo.toml file, but found cargo.toml please try to rename it to Cargo.toml. \
                     --path must point to a directory containing a Cargo.toml file.",
                            src.path().display()
                        )
                    } else {
                        bail!(
                            "`{}` does not contain a Cargo.toml file. \
                     --path must point to a directory containing a Cargo.toml file.",
                            src.path().display()
                        )
                    }
                }
                select_pkg(
                    &mut src,
                    dep,
                    |path: &mut PathSource<'_>| path.read_packages(),
                    config,
                )?
            } else if let Some(dep) = dep {
                let mut source = map.load(source_id, &HashSet::new())?;
                if let Ok(Some(pkg)) = installed_exact_package(
                    dep.clone(),
                    &mut source,
                    config,
                    opts,
                    &root,
                    &dst,
                    force,
                ) {
                    let msg = format!(
                        "package `{}` is already installed, use --force to override",
                        pkg
                    );
                    config.shell().status("Ignored", &msg)?;
                    return Ok(None);
                }
                select_dep_pkg(&mut source, dep, config, needs_update_if_source_is_index)?
            } else {
                bail!(
                    "must specify a crate to install from \
                         crates.io, or use --path or --git to \
                         specify alternate source"
                )
            }
        };

        let (ws, rustc, target) = make_ws_rustc_target(config, opts, &source_id, pkg.clone())?;
        // If we're installing in --locked mode and there's no `Cargo.lock` published
        // ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
        if config.locked() && !ws.root().join("Cargo.lock").exists() {
            config.shell().warn(format!(
                "no Cargo.lock file published in {}",
                pkg.to_string()
            ))?;
        }
        let pkg = if source_id.is_git() {
            // Don't use ws.current() in order to keep the package source as a git source so that
            // install tracking uses the correct source.
            pkg
        } else {
            ws.current()?.clone()
        };

        if from_cwd {
            if pkg.manifest().edition() == Edition::Edition2015 {
                config.shell().warn(
                    "Using `cargo install` to install the binaries for the \
                     package in current working directory is deprecated, \
                     use `cargo install --path .` instead. \
                     Use `cargo build` if you want to simply build the package.",
                )?
            } else {
                bail!(
                    "Using `cargo install` to install the binaries for the \
                     package in current working directory is no longer supported, \
                     use `cargo install --path .` instead. \
                     Use `cargo build` if you want to simply build the package."
                )
            }
        };

        // For bare `cargo install` (no `--bin` or `--example`), check if there is
        // *something* to install. Explicit `--bin` or `--example` flags will be
        // checked at the start of `compile_ws`.
        if !opts.filter.is_specific() && !pkg.targets().iter().any(|t| t.is_bin()) {
            bail!(
                "there is nothing to install in `{}`, because it has no binaries\n\
                 `cargo install` is only for installing programs, and can't be used with libraries.\n\
                 To use a library crate, add it as a dependency in a Cargo project instead.",
                pkg
            );
        }

        let ip = InstallablePackage {
            config,
            opts,
            root,
            source_id,
            vers,
            force,
            no_track,

            pkg,
            ws,
            rustc,
            target,
        };

        // WARNING: no_track does not perform locking, so there is no protection
        // of concurrent installs.
        if no_track {
            // Check for conflicts.
            ip.no_track_duplicates(&dst)?;
        } else if is_installed(
            &ip.pkg, config, opts, &ip.rustc, &ip.target, &ip.root, &dst, force,
        )? {
            let msg = format!(
                "package `{}` is already installed, use --force to override",
                ip.pkg
            );
            config.shell().status("Ignored", &msg)?;
            return Ok(None);
        }

        Ok(Some(ip))
    }
// Returns pkg to install. None if pkg is already installed
Returns pkg to install. None if pkg is already installed
Returns pkg to install . None if pkg is already installed
pub fn new(
        config: &'cfg Config,
        root: Filesystem,
        map: SourceConfigMap<'_>,
        krate: Option<&str>,
        source_id: SourceId,
        from_cwd: bool,
        vers: Option<&'a str>,
        opts: &'a ops::CompileOptions,
        force: bool,
        no_track: bool,
        needs_update_if_source_is_index: bool,
    ) -> CargoResult<Option<InstallablePackage<'cfg, 'a>>> {
        if let Some(name) = krate {
            if name == "." {
                bail!(
                    "To install the binaries for the package in current working \
                     directory use `cargo install --path .`. \
                     Use `cargo build` if you want to simply build the package."
                )
            }
        }
        let dst = root.join("bin").into_path_unlocked();
        let pkg = {
            let dep = {
                if let Some(krate) = krate {
                    let vers = if let Some(vers_flag) = vers {
                        Some(parse_semver_flag(vers_flag)?.to_string())
                    } else if source_id.is_registry() {
                        // Avoid pre-release versions from crate.io
                        // unless explicitly asked for
                        Some(String::from("*"))
                    } else {
                        None
                    };
                    Some(Dependency::parse(krate, vers.as_deref(), source_id)?)
                } else {
                    None
                }
            };
            if source_id.is_git() {
                let mut source = GitSource::new(source_id, config)?;
                select_pkg(
                    &mut source,
                    dep,
                    |git: &mut GitSource<'_>| git.read_packages(),
                    config,
                )?
            } else if source_id.is_path() {
                let mut src = path_source(source_id, config)?;
                if !src.path().is_dir() {
                    bail!(
                        "`{}` is not a directory. \
                     --path must point to a directory containing a Cargo.toml file.",
                        src.path().display()
                    )
                }
                if !src.path().join("Cargo.toml").exists() {
                    if from_cwd {
                        bail!(
                            "`{}` is not a crate root; specify a crate to \
                         install from crates.io, or use --path or --git to \
                         specify an alternate source",
                            src.path().display()
                        );
                    } else if src.path().join("cargo.toml").exists() {
                        bail!(
                            "`{}` does not contain a Cargo.toml file, but found cargo.toml please try to rename it to Cargo.toml. \
                     --path must point to a directory containing a Cargo.toml file.",
                            src.path().display()
                        )
                    } else {
                        bail!(
                            "`{}` does not contain a Cargo.toml file. \
                     --path must point to a directory containing a Cargo.toml file.",
                            src.path().display()
                        )
                    }
                }
                select_pkg(
                    &mut src,
                    dep,
                    |path: &mut PathSource<'_>| path.read_packages(),
                    config,
                )?
            } else if let Some(dep) = dep {
                let mut source = map.load(source_id, &HashSet::new())?;
                if let Ok(Some(pkg)) = installed_exact_package(
                    dep.clone(),
                    &mut source,
                    config,
                    opts,
                    &root,
                    &dst,
                    force,
                ) {
                    let msg = format!(
                        "package `{}` is already installed, use --force to override",
                        pkg
                    );
                    config.shell().status("Ignored", &msg)?;
                    return Ok(None);
                }
                select_dep_pkg(&mut source, dep, config, needs_update_if_source_is_index)?
            } else {
                bail!(
                    "must specify a crate to install from \
                         crates.io, or use --path or --git to \
                         specify alternate source"
                )
            }
        };
        let (ws, rustc, target) = make_ws_rustc_target(config, opts, &source_id, pkg.clone())?;
        // If we're installing in --locked mode and there's no `Cargo.lock` published
        // ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
        if config.locked() && !ws.root().join("Cargo.lock").exists() {
            config.shell().warn(format!(
                "no Cargo.lock file published in {}",
                pkg.to_string()
            ))?;
        }
        let pkg = if source_id.is_git() {
            // Don't use ws.current() in order to keep the package source as a git source so that
            // install tracking uses the correct source.
            pkg
        } else {
            ws.current()?.clone()
        };
        if from_cwd {
            if pkg.manifest().edition() == Edition::Edition2015 {
                config.shell().warn(
                    "Using `cargo install` to install the binaries for the \
                     package in current working directory is deprecated, \
                     use `cargo install --path .` instead. \
                     Use `cargo build` if you want to simply build the package.",
                )?
            } else {
                bail!(
                    "Using `cargo install` to install the binaries for the \
                     package in current working directory is no longer supported, \
                     use `cargo install --path .` instead. \
                     Use `cargo build` if you want to simply build the package."
                )
            }
        };
        // For bare `cargo install` (no `--bin` or `--example`), check if there is
        // *something* to install. Explicit `--bin` or `--example` flags will be
        // checked at the start of `compile_ws`.
        if !opts.filter.is_specific() && !pkg.targets().iter().any(|t| t.is_bin()) {
            bail!(
                "there is nothing to install in `{}`, because it has no binaries\n\
                 `cargo install` is only for installing programs, and can't be used with libraries.\n\
                 To use a library crate, add it as a dependency in a Cargo project instead.",
                pkg
            );
        }
        let ip = InstallablePackage {
            config,
            opts,
            root,
            source_id,
            vers,
            force,
            no_track,
            pkg,
            ws,
            rustc,
            target,
        };
        // WARNING: no_track does not perform locking, so there is no protection
        // of concurrent installs.
        if no_track {
            // Check for conflicts.
            ip.no_track_duplicates(&dst)?;
        } else if is_installed(
            &ip.pkg, config, opts, &ip.rustc, &ip.target, &ip.root, &dst, force,
        )? {
            let msg = format!(
                "package `{}` is already installed, use --force to override",
                ip.pkg
            );
            config.shell().status("Ignored", &msg)?;
            return Ok(None);
        }
        Ok(Some(ip))
    }
pub fn new ( config : & ' cfg Config , root : Filesystem , map : SourceConfigMap < ' _ > , krate : Option < & str > , source_id : SourceId , from_cwd : bool , vers : Option < & ' a str > , opts : & ' a ops :: CompileOptions , force : bool , no_track : bool , needs_update_if_source_is_index : bool , ) -> CargoResult < Option < InstallablePackage < ' cfg , ' a > > > { if let Some ( name ) = krate { if name == " " { bail ! ( " \
 \
 " ) } } let dst = root . join ( " " ) . into_path_unlocked ( ) ; let pkg = { let dep = { if let Some ( krate ) = krate { let vers = if let Some ( vers_flag ) = vers { Some ( parse_semver_flag ( vers_flag ) ? . to_string ( ) ) } else if source_id . is_registry ( ) { // Avoid pre-release versions from crate.io // unless explicitly asked for Some ( String :: from ( " " ) ) } else { None } ; Some ( Dependency :: parse ( krate , vers . as_deref ( ) , source_id ) ? ) } else { None } } ; if source_id . is_git ( ) { let mut source = GitSource :: new ( source_id , config ) ? ; select_pkg ( & mut source , dep , | git : & mut GitSource < ' _ > | git . read_packages ( ) , config , ) ? } else if source_id . is_path ( ) { let mut src = path_source ( source_id , config ) ? ; if ! src . path ( ) . is_dir ( ) { bail ! ( " \
 " src path ( ) display ( ) ) } if ! src . path ( ) . join ( " " ) . exists ( ) { if from_cwd { bail ! ( " \
 \
 " src path ( ) display ( ) ) ; } else if src . path ( ) . join ( " " ) . exists ( ) { bail ! ( " \
 " src path ( ) display ( ) ) } else { bail ! ( " \
 " src path ( ) display ( ) ) } } select_pkg ( & mut src , dep , | path : & mut PathSource < ' _ > | path . read_packages ( ) , config , ) ? } else if let Some ( dep ) = dep { let mut source = map . load ( source_id , & HashSet :: new ( ) ) ? ; if let Ok ( Some ( pkg ) ) = installed_exact_package ( dep . clone ( ) , & mut source , config , opts , & root , & dst , force , ) { let msg = format ! ( " " pkg ) ; config . shell ( ) . status ( " " , & msg ) ? ; return Ok ( None ) ; } select_dep_pkg ( & mut source , dep , config , needs_update_if_source_is_index ) ? } else { bail ! ( " \
 \
 " ) } } ; let ( ws , rustc , target ) = make_ws_rustc_target ( config , opts , & source_id , pkg . clone ( ) ) ? ; // If we're installing in --locked mode and there's no `Cargo.lock` published // ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026 if config . locked ( ) && ! ws . root ( ) . join ( " " ) . exists ( ) { config . shell ( ) . warn ( format ! ( " " pkg to_string ( ) ) ) ? ; } let pkg = if source_id . is_git ( ) { // Don't use ws.current() in order to keep the package source as a git source so that // install tracking uses the correct source. pkg } else { ws . current ( ) ? . clone ( ) } ; if from_cwd { if pkg . manifest ( ) . edition ( ) == Edition :: Edition2015 { config . shell ( ) . warn ( " \
 \
 \
 " , ) ? } else { bail ! ( " \
 \
 \
 " ) } } ; // For bare `cargo install` (no `--bin` or `--example`), check if there is // *something* to install. Explicit `--bin` or `--example` flags will be // checked at the start of `compile_ws`. if ! opts . filter . is_specific ( ) && ! pkg . targets ( ) . iter ( ) . any ( | t | t . is_bin ( ) ) { bail ! ( " \n \
 \n \
 " pkg ) ; } let ip = InstallablePackage { config , opts , root , source_id , vers , force , no_track , pkg , ws , rustc , target , } ; // WARNING: no_track does not perform locking, so there is no protection // of concurrent installs. if no_track { // Check for conflicts. ip . no_track_duplicates ( & dst ) ? ; } else if is_installed ( & ip . pkg , config , opts , & ip . rustc , & ip . target , & ip . root , & dst , force , ) ? { let msg = format ! ( " " ip pkg ) ; config . shell ( ) . status ( " " , & msg ) ? ; return Ok ( None ) ; } Ok ( Some ( ip ) ) }
Returns pkg to install.
Returns pkg to install .
config
&'cfg Config
root
Filesystem
map
SourceConfigMap<'_>
krate
Option<&str>
source_id
SourceId
from_cwd
bool
vers
Option<&'a str>
opts
&'a ops::CompileOptions
force
bool
no_track
bool
needs_update_if_source_is_index
bool
config
&'cfg Config
root
Filesystem
map
SourceConfigMap<'_>
krate
Option<&str>
source_id
SourceId
from_cwd
bool
vers
Option<&'a str>
opts
&'a ops::CompileOptions
force
bool
no_track
bool
needs_update_if_source_is_index
bool