use hammer::FlagConfig;
use cargo::{execute_main_without_stdin,CLIResult,CLIError};
-use cargo::core::{Package,SourceId};
+use cargo::core::{Package,Source,SourceId};
use cargo::sources::{PathSource};
#[deriving(PartialEq,Clone,Decodable)]
fn execute(options: Options) -> CLIResult<Option<Package>> {
let source_id = SourceId::for_path(&Path::new(options.manifest_path.as_slice()));
+ let mut source = PathSource::new(&source_id);
- PathSource::new(&source_id)
+ try!(source.update().map_err(|err| CLIError::new(err.get_desc(), Some(err.get_detail()), 1)));
+
+ source
.get_root_package()
.map(|pkg| Some(pkg))
.map_err(|err| CLIError::new(err.get_desc(), Some(err.get_detail()), 1))
use std::os;
use util::config::{ConfigValue};
-use core::{SourceId,PackageSet,resolver};
+use core::{Source,SourceId,PackageSet,resolver};
use core::registry::PackageRegistry;
use ops;
use sources::{PathSource};
pub fn compile(manifest_path: &Path) -> CargoResult<()> {
log!(4, "compile; manifest-path={}", manifest_path.display());
+ let mut source = PathSource::new(&SourceId::for_path(&manifest_path.dir_path()));
+
+ try!(source.update());
+
// TODO: Move this into PathSource
- let package = try!(PathSource::new(&SourceId::for_path(&manifest_path.dir_path())).get_root_package());
+ let package = try!(source.get_root_package());
debug!("loaded package; package={}", package);
let override_ids = try!(source_ids_from_config());
pub struct PathSource {
id: SourceId,
- path: Path,
+ updated: bool,
+ packages: Vec<Package>
}
/**
log!(5, "new; id={}", id);
assert!(id.is_path(), "does not represent a path source; id={}", id);
- let path = Path::new(id.get_url().path.as_slice());
-
PathSource {
id: id.clone(),
- path: path
+ updated: false,
+ packages: Vec::new()
}
}
+ fn path(&self) -> Path {
+ Path::new(self.id.get_url().path.as_slice())
+ }
+
pub fn get_root_package(&self) -> CargoResult<Package> {
log!(5, "get_root_package; source={}", self);
- match (try!(self.packages())).as_slice().head() {
+ if !self.updated {
+ return Err(simple_human("source has not been updated"))
+ }
+
+ match self.packages.as_slice().head() {
Some(pkg) => Ok(pkg.clone()),
None => Err(simple_human("no package found in source"))
}
}
-
- fn packages(&self) -> CargoResult<Vec<Package>> {
- ops::read_packages(&self.path, &self.id)
- }
}
impl Show for PathSource {
impl Source for PathSource {
fn update(&mut self) -> CargoResult<()> {
+ if !self.updated {
+ let pkgs = try!(ops::read_packages(&self.path(), &self.id));
+ self.packages.push_all_move(pkgs);
+ self.updated = true;
+ }
+
Ok(())
}
fn list(&self) -> CargoResult<Vec<Summary>> {
- let pkgs = try!(self.packages());
- Ok(pkgs.iter().map(|p| p.get_summary().clone()).collect())
+ Ok(self.packages.iter()
+ .map(|p| p.get_summary().clone())
+ .collect())
}
fn download(&self, _: &[PackageId]) -> CargoResult<()>{
fn get(&self, ids: &[PackageId]) -> CargoResult<Vec<Package>> {
log!(5, "getting packages; ids={}", ids);
- let pkgs = try!(self.packages());
-
- Ok(pkgs.iter()
+ Ok(self.packages.iter()
.filter(|pkg| ids.iter().any(|id| pkg.get_package_id() == id))
.map(|pkg| pkg.clone())
.collect())