Ok(())
}
- pub fn add_preloaded(&mut self, id: &SourceId, source: Box<Source + 'cfg>) {
- self.add_source(id, source, Kind::Locked);
+ pub fn add_preloaded(&mut self, source: Box<Source + 'cfg>) {
+ self.add_source(source, Kind::Locked);
}
- fn add_source(&mut self, id: &SourceId, source: Box<Source + 'cfg>,
+ fn add_source(&mut self, source: Box<Source + 'cfg>,
kind: Kind) {
- self.sources.insert(id, source);
- self.source_ids.insert(id.clone(), (id.clone(), kind));
+ let id = source.source_id().clone();
+ self.sources.insert(source);
+ self.source_ids.insert(id.clone(), (id, kind));
}
- pub fn add_override(&mut self, id: &SourceId, source: Box<Source + 'cfg>) {
- self.add_source(id, source, Kind::Override);
- self.overrides.push(id.clone());
+ pub fn add_override(&mut self, source: Box<Source + 'cfg>) {
+ self.overrides.push(source.source_id().clone());
+ self.add_source(source, Kind::Override);
}
pub fn register_lock(&mut self, id: PackageId, deps: Vec<PackageId>) {
fn load(&mut self, source_id: &SourceId, kind: Kind) -> CargoResult<()> {
(|| {
let source = self.source_config.load(source_id)?;
+ assert_eq!(source.source_id(), source_id);
if kind == Kind::Override {
self.overrides.push(source_id.clone());
}
- self.add_source(source_id, source, kind);
+ self.add_source(source, kind);
// Ensure the source has fetched all necessary remote data.
let _p = profile::start(format!("updating: {}", source_id));
/// A Source finds and downloads remote packages based on names and
/// versions.
pub trait Source: Registry {
+ fn source_id(&self) -> &SourceId;
+
/// The update method performs any network operations required to
/// get the entire list of all names, versions and dependencies of
/// packages managed by the Source.
}
impl<'a, T: Source + ?Sized + 'a> Source for Box<T> {
+ fn source_id(&self) -> &SourceId {
+ (**self).source_id()
+ }
+
fn update(&mut self) -> CargoResult<()> {
(**self).update()
}
self.get(pkg_id.source_id())
}
- pub fn insert(&mut self, id: &SourceId, source: Box<Source + 'src>) {
- self.map.insert(id.clone(), source);
+ pub fn insert(&mut self, source: Box<Source + 'src>) {
+ let id = source.source_id().clone();
+ self.map.insert(id, source);
}
pub fn is_empty(&self) -> bool {
let mut registry = PackageRegistry::new(ws.config())?;
- let mut write_lockfile = true;
+ // Avoid writing a lockfile if we are `cargo install`ing a non local package.
+ let write_lockfile = source.is_none() || ws.current_opt().is_none();
+
if let Some(source) = source {
- if let Some(root_package) = ws.current_opt() {
- // Avoid writing a lockfile if we are `cargo install`ing a non local package.
- write_lockfile = false;
- registry.add_preloaded(root_package.package_id().source_id(), source);
- }
+ registry.add_preloaded(source);
}
// First, resolve the root_package's *listed* dependencies, as well as
(defined in `{}`)", path.display(),
definition.display()))
})?;
- registry.add_override(&id, Box::new(source));
+ registry.add_override(Box::new(source));
}
Ok(())
}
use util::paths;
pub struct DirectorySource<'cfg> {
- id: SourceId,
+ source_id: SourceId,
root: PathBuf,
packages: HashMap<PackageId, (Package, Checksum)>,
config: &'cfg Config,
pub fn new(path: &Path, id: &SourceId, config: &'cfg Config)
-> DirectorySource<'cfg> {
DirectorySource {
- id: id.clone(),
+ source_id: id.clone(),
root: path.to_path_buf(),
config: config,
packages: HashMap::new(),
}
impl<'cfg> Source for DirectorySource<'cfg> {
+ fn source_id(&self) -> &SourceId {
+ &self.source_id
+ }
+
fn update(&mut self) -> CargoResult<()> {
self.packages.clear();
let entries = self.root.read_dir().chain_error(|| {
for entry in entries {
let entry = entry?;
let path = entry.path();
- let mut src = PathSource::new(&path,
- &self.id,
- self.config);
+ let mut src = PathSource::new(&path, &self.source_id, self.config);
src.update()?;
let pkg = src.root_package()?;
}
impl<'cfg> Source for GitSource<'cfg> {
+ fn source_id(&self) -> &SourceId {
+ &self.source_id
+ }
+
fn update(&mut self) -> CargoResult<()> {
let lock = self.config.git_path()
.open_rw(".cargo-lock-git", self.config, "the git checkouts")?;
use util::Config;
pub struct PathSource<'cfg> {
- id: SourceId,
+ source_id: SourceId,
path: PathBuf,
updated: bool,
packages: Vec<Package>,
pub fn new(path: &Path, id: &SourceId, config: &'cfg Config)
-> PathSource<'cfg> {
PathSource {
- id: id.clone(),
+ source_id: id.clone(),
path: path.to_path_buf(),
updated: false,
packages: Vec::new(),
if self.updated {
Ok(self.packages.clone())
} else if self.recursive {
- ops::read_packages(&self.path, &self.id, self.config)
+ ops::read_packages(&self.path, &self.source_id, self.config)
} else {
let path = self.path.join("Cargo.toml");
- let (pkg, _) = ops::read_package(&path, &self.id,
- self.config)?;
+ let (pkg, _) = ops::read_package(&path, &self.source_id, self.config)?;
Ok(vec![pkg])
}
}
}
impl<'cfg> Source for PathSource<'cfg> {
+ fn source_id(&self) -> &SourceId {
+ &self.source_id
+ }
+
fn update(&mut self) -> CargoResult<()> {
if !self.updated {
let packages = self.read_packages()?;
}
impl<'cfg> Source for RegistrySource<'cfg> {
+ fn source_id(&self) -> &SourceId {
+ &self.source_id
+ }
+
fn update(&mut self) -> CargoResult<()> {
// If we have an imprecise version then we don't know what we're going
// to look for, so we always attempt to perform an update here.
}
impl<'cfg> Source for ReplacedSource<'cfg> {
+ fn source_id(&self) -> &SourceId {
+ &self.to_replace
+ }
+
fn update(&mut self) -> CargoResult<()> {
self.inner.update().chain_error(|| {
human(format!("failed to update replaced source `{}`",