From ef07b81617df855328c34365b28049cd9742946c Mon Sep 17 00:00:00 2001 From: Jason Priest Date: Tue, 9 Jun 2015 23:11:51 -0500 Subject: [PATCH] Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). --- src/cargo/ops/registry.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 89c9ed020a4..960589857a0 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -51,13 +51,8 @@ pub fn publish(manifest_path: &Path, false, true)).unwrap(); // Upload said tarball to the specified destination - // However, do not upload if performing a dry run try!(config.shell().status("Uploading", pkg.package_id().to_string())); - if !dry { - try!(transmit(&pkg, &tarball, &mut registry)); - } else { - try!(config.shell().warn("Aborting upload due to dry run")); - } + try!(transmit(config, &pkg, &tarball, &mut registry, dry)); Ok(()) } @@ -83,8 +78,11 @@ fn verify_dependencies(pkg: &Package, registry_src: &SourceId) Ok(()) } -fn transmit(pkg: &Package, tarball: &Path, registry: &mut Registry) - -> CargoResult<()> { +fn transmit(config: &Config, + pkg: &Package, + tarball: &Path, + registry: &mut Registry, + dry: bool) -> CargoResult<()> { let deps = pkg.dependencies().iter().map(|dep| { NewCrateDependency { optional: dep.is_optional(), @@ -127,6 +125,13 @@ fn transmit(pkg: &Package, tarball: &Path, registry: &mut Registry) } None => {} } + + // Do not upload if performing a dry run + if dry { + try!(config.shell().warn("Aborting upload due to dry run")); + return Ok(()); + } + registry.publish(&NewCrate { name: pkg.name().to_string(), vers: pkg.version().to_string(),