diff --git a/src/controllers/krate/publish.rs b/src/controllers/krate/publish.rs index 8ff5d8b85c4..2ac0d00cc00 100644 --- a/src/controllers/krate/publish.rs +++ b/src/controllers/krate/publish.rs @@ -51,25 +51,6 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult) -> bool { - s.map_or(true, String::is_empty) - } - - // It can have up to three elements per below conditions. - let mut missing = Vec::with_capacity(3); - - if empty(metadata.description.as_ref()) { - missing.push("description"); - } - if empty(metadata.license.as_ref()) && empty(metadata.license_file.as_ref()) { - missing.push("license"); - } - if !missing.is_empty() { - let message = missing_metadata_error_message(&missing); - return Err(cargo_err(&message)); - } - conduit_compat(move || { let conn = &mut *app.db_write()?; @@ -110,6 +91,51 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult maximums.max_upload_size { + return Err(cargo_err(&format_args!( + "max upload size is: {}", + maximums.max_upload_size + ))); + } + + let pkg_name = format!("{}-{}", &*metadata.name, &*metadata.vers); + let tarball_info = process_tarball(&pkg_name, &*tarball_bytes, maximums.max_unpack_size)?; + + // `unwrap()` is safe here since `process_tarball()` validates that + // we only accept manifests with a `package` section and without + // inheritance. + let package = tarball_info.manifest.package.unwrap(); + + let description = package.description.map(|it| it.as_local().unwrap()); + let license = package.license.map(|it| it.as_local().unwrap()); + let license_file = package.license_file.map(|it| it.as_local().unwrap()); + + // Make sure required fields are provided + fn empty(s: Option<&String>) -> bool { + s.map_or(true, String::is_empty) + } + + // It can have up to three elements per below conditions. + let mut missing = Vec::with_capacity(3); + if empty(description.as_ref()) { + missing.push("description"); + } + if empty(license.as_ref()) && empty(license_file.as_ref()) { + missing.push("license"); + } + if !missing.is_empty() { + let message = missing_metadata_error_message(&missing); + return Err(cargo_err(&message)); + } + // Create a transaction on the database, if there are no errors, // commit the transactions to record a new or updated crate. conn.transaction(|conn| { @@ -136,7 +162,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult AppResult AppResult maximums.max_upload_size { - return Err(cargo_err(&format_args!( - "max upload size is: {}", - maximums.max_upload_size - ))); - } - // Read tarball from request let hex_cksum: String = Sha256::digest(&tarball_bytes).encode_hex(); - let pkg_name = format!("{}-{}", krate.name, vers); - let tarball_info = - process_tarball(&pkg_name, &*tarball_bytes, maximums.max_unpack_size)?; - - // `unwrap()` is safe here since `process_tarball()` validates that - // we only accept manifests with a `package` section and without - // inheritance. - let package = tarball_info.manifest.package.unwrap(); let rust_version = package.rust_version.map(|rv| rv.as_local().unwrap()); // Persist the new version of this crate @@ -215,7 +218,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult, pub features: BTreeMap>, - pub description: Option, pub homepage: Option, pub documentation: Option, pub readme: Option, @@ -27,8 +26,6 @@ pub struct PublishMetadata { pub keywords: EncodableKeywordList, #[serde(default)] pub categories: EncodableCategoryList, - pub license: Option, - pub license_file: Option, pub repository: Option, #[serde(default)] pub links: Option,