Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Source::download_now #6637

Merged
merged 1 commit into from
Feb 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/cargo/core/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::collections::hash_map::HashMap;
use std::fmt;

use crate::core::{Dependency, Package, PackageId, Summary};
use crate::util::CargoResult;
use crate::core::package::PackageSet;
use crate::util::{CargoResult, Config};

mod source_id;

Expand Down Expand Up @@ -51,6 +52,16 @@ pub trait Source {
/// version specified.
fn download(&mut self, package: PackageId) -> CargoResult<MaybePackage>;

fn download_now(self: Box<Self>, package: PackageId, config: &Config) -> CargoResult<Package>
where
Self: std::marker::Sized,
{
let mut sources = SourceMap::new();
sources.insert(self);
let pkg_set = PackageSet::new(&[package], sources, config)?;
Ok(pkg_set.get_one(package)?.clone())
}

fn finish_download(&mut self, package: PackageId, contents: Vec<u8>) -> CargoResult<Package>;

/// Generates a unique string which represents the fingerprint of the
Expand Down
20 changes: 6 additions & 14 deletions src/cargo/ops/common_for_install_and_uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use std::path::{Path, PathBuf};
use semver::VersionReq;
use serde::{Deserialize, Serialize};

use crate::core::package::PackageSet;
use crate::core::source::SourceMap;
use crate::core::PackageId;
use crate::core::{Dependency, Package, Source, SourceId};
use crate::sources::PathSource;
Expand Down Expand Up @@ -139,8 +137,11 @@ where
};
let dep = Dependency::parse_no_deprecated(name, vers_spec, source.source_id())?;
let deps = source.query_vec(&dep)?;
let pkgid = match deps.iter().map(|p| p.package_id()).max() {
Some(pkgid) => pkgid,
match deps.iter().map(|p| p.package_id()).max() {
Some(pkgid) => {
let pkg = Box::new(&mut source).download_now(pkgid, config)?;
Ok((pkg, Box::new(source)))
},
None => {
let vers_info = vers
.map(|v| format!(" with version `{}`", v))
Expand All @@ -152,16 +153,7 @@ where
vers_info
)
}
};

let pkg = {
let mut map = SourceMap::new();
map.insert(Box::new(&mut source));
PackageSet::new(&[pkgid], map, config)?
.get_one(pkgid)?
.clone()
};
Ok((pkg, Box::new(source)))
}
}
None => {
let candidates = list_all(&mut source)?;
Expand Down