Skip to content

Commit

Permalink
bldr upload now uploads dependencies
Browse files Browse the repository at this point in the history
This fixes bldr upload to now correctly deal with dependencies.

* If a dependency doesn't exist in the depot, we check for an archive in
  the same directory as the archive you specified on the command line,
  and upload it
* If everything is present, it doesn't upload anything
  • Loading branch information
adamhjk committed Mar 16, 2016
1 parent 8b38e9b commit 872c05d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
52 changes: 50 additions & 2 deletions components/bldr/src/command/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,57 @@ static LOGKEY: &'static str = "CU";
/// * Fails if it cannot upload the file
pub fn package(config: &Config) -> BldrResult<()> {
let url = config.url().as_ref().unwrap();
let mut archive_path = PathBuf::from(config.archive().clone());
archive_path.pop();
let mut pa = PackageArchive::new(PathBuf::from(config.archive()));
outputln!("Uploading from {}", pa.path.to_string_lossy());
outputln!("Checking that all dependencies are in the depot...");
let tdeps = try!(pa.tdeps());
for dep in tdeps.iter() {
match depot::client::show_package(url, dep) {
Ok(_) => outputln!("{} is present", dep),
Err(BldrError{ err: ErrorKind::RemotePackageNotFound(_), .. }) => {
let dep_path = PathBuf::from(format!("{}/{}",
archive_path.to_string_lossy(),
dep.archive_name().unwrap()));
if dep_path.is_file() {
outputln!("Uploading {} from {}", dep, dep_path.to_string_lossy());
let mut dpa = PackageArchive::new(dep_path);
match upload(&mut dpa, &url) {
Ok(()) => {}
Err(e @ BldrError{ err: ErrorKind::HTTP(_), .. }) => return Err(e),
Err(e @ BldrError{ err: ErrorKind::PackageArchiveMalformed(_), .. }) => {
return Err(e)
}
Err(_) => {
// This is because of a bug where the depot and client code seem to not
// correctly deal with conflicts.
outputln!("Trying the next package anyway...");
}
}
} else {
outputln!("Cannot find an archive for {} at {}",
dep.archive_name().unwrap(),
archive_path.to_string_lossy());
return Err(bldr_error!(ErrorKind::FileNotFound(archive_path.to_string_lossy()
.into_owned())));
}
}
Err(e) => return Err(e),
}
}
let ident = try!(pa.ident());
match depot::client::show_package(url, &ident) {
Ok(_) => outputln!("{} is present", ident),
Err(_) => {
outputln!("Uploading {} from {}", ident, pa.path.to_string_lossy());
try!(upload(&mut pa, &url));
outputln!("Complete");
}
}
Ok(())
}

pub fn upload(mut pa: &mut PackageArchive, url: &str) -> BldrResult<()> {
match depot::client::put_package(url, &mut pa) {
Ok(()) => (),
Err(BldrError{err: ErrorKind::HTTP(StatusCode::Conflict), ..}) => {
Expand All @@ -60,6 +109,5 @@ pub fn package(config: &Config) -> BldrResult<()> {
return Err(e);
}
}
outputln!("Complete");
Ok(())
}
12 changes: 12 additions & 0 deletions components/bldr/src/package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ impl PackageIdent {
}
}

pub fn archive_name(&self) -> Option<String> {
if self.fully_qualified() {
Some(format!("{}-{}-{}-{}.bldr",
self.origin,
self.name,
self.version.as_ref().unwrap(),
self.release.as_ref().unwrap()))
} else {
None
}
}

pub fn fully_qualified(&self) -> bool {
self.version.is_some() && self.release.is_some()
}
Expand Down

1 comment on commit 872c05d

@chef-delivery
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delivery Status:

Verify Build Acceptance
<a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/verify', target='_blank'><img src='https://img.shields.io/badge/Unit-Passed-brightgreen.svg', alt='Unit'> <a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/build', target='_blank'><img src='https://img.shields.io/badge/Unit-Passed-brightgreen.svg', alt='Unit'> <a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/acceptance', target='_blank'><img src='https://img.shields.io/badge/Provision-Passed-brightgreen.svg', alt='Provision'>
<a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/verify', target='_blank'><img src='https://img.shields.io/badge/Lint-Passed-brightgreen.svg', alt='Lint'> <a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/build', target='_blank'><img src='https://img.shields.io/badge/Lint-Passed-brightgreen.svg', alt='Lint'> <a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/acceptance', target='_blank'><img src='https://img.shields.io/badge/Deploy-Skipped-lightgrey.svg', alt='Deploy'>
<a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/verify', target='_blank'><img src='https://img.shields.io/badge/Syntax-Skipped-lightgrey.svg', alt='Syntax'> <a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/build', target='_blank'><img src='https://img.shields.io/badge/Syntax-Skipped-lightgrey.svg', alt='Syntax'> <a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/acceptance', target='_blank'><img src='https://img.shields.io/badge/Smoke-Skipped-lightgrey.svg', alt='Smoke'>
<a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/build', target='_blank'><img src='https://img.shields.io/badge/Quality-Skipped-lightgrey.svg', alt='Quality'> <a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/acceptance', target='_blank'><img src='https://img.shields.io/badge/Functional-Passed-brightgreen.svg', alt='Functional'>
<a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/build', target='_blank'><img src='https://img.shields.io/badge/Security-Skipped-lightgrey.svg', alt='Security'>
<a href='https://delivery.chef.co/e/chef/#/organizations/bldr/projects/bldr/changes/17718763-4ad6-4f95-ae81-2cd11175dcef/status/build', target='_blank'><img src='https://img.shields.io/badge/Publish-Skipped-lightgrey.svg', alt='Publish'>

Please sign in to comment.