Skip to content

Commit 1ffba95

Browse files
committed
controllers/krate/publish: Move process_tarball() call ahead of INSERT SQL queries
This will allow us to use the data from the `Cargo.toml` file in the tarball instead of the JSON metadata blob.
1 parent f6e5a86 commit 1ffba95

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/controllers/krate/publish.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
125125
)));
126126
}
127127

128+
let pkg_name = format!("{}-{}", &*metadata.name, &*metadata.vers);
129+
let tarball_info = process_tarball(&pkg_name, &*tarball_bytes, maximums.max_unpack_size)?;
130+
131+
// `unwrap()` is safe here since `process_tarball()` validates that
132+
// we only accept manifests with a `package` section and without
133+
// inheritance.
134+
let package = tarball_info.manifest.package.unwrap();
135+
128136
// Create a transaction on the database, if there are no errors,
129137
// commit the transactions to record a new or updated crate.
130138
conn.transaction(|conn| {
@@ -195,14 +203,6 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
195203
// Read tarball from request
196204
let hex_cksum: String = Sha256::digest(&tarball_bytes).encode_hex();
197205

198-
let pkg_name = format!("{}-{}", krate.name, vers);
199-
let tarball_info =
200-
process_tarball(&pkg_name, &*tarball_bytes, maximums.max_unpack_size)?;
201-
202-
// `unwrap()` is safe here since `process_tarball()` validates that
203-
// we only accept manifests with a `package` section and without
204-
// inheritance.
205-
let package = tarball_info.manifest.package.unwrap();
206206
let rust_version = package.rust_version.map(|rv| rv.as_local().unwrap());
207207

208208
// Persist the new version of this crate

0 commit comments

Comments
 (0)