@@ -51,25 +51,6 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
5151 request_log. add ( "crate_name" , & * metadata. name ) ;
5252 request_log. add ( "crate_version" , & * metadata. vers ) ;
5353
54- // Make sure required fields are provided
55- fn empty ( s : Option < & String > ) -> bool {
56- s. map_or ( true , String :: is_empty)
57- }
58-
59- // It can have up to three elements per below conditions.
60- let mut missing = Vec :: with_capacity ( 3 ) ;
61-
62- if empty ( metadata. description . as_ref ( ) ) {
63- missing. push ( "description" ) ;
64- }
65- if empty ( metadata. license . as_ref ( ) ) && empty ( metadata. license_file . as_ref ( ) ) {
66- missing. push ( "license" ) ;
67- }
68- if !missing. is_empty ( ) {
69- let message = missing_metadata_error_message ( & missing) ;
70- return Err ( cargo_err ( & message) ) ;
71- }
72-
7354 conduit_compat ( move || {
7455 let conn = & mut * app. db_write ( ) ?;
7556
@@ -110,6 +91,51 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
11091 app. rate_limiter
11192 . check_rate_limit ( user. id , rate_limit_action, conn) ?;
11293
94+ let content_length = tarball_bytes. len ( ) as u64 ;
95+
96+ let maximums = Maximums :: new (
97+ existing_crate. as_ref ( ) . and_then ( |c| c. max_upload_size ) ,
98+ app. config . max_upload_size ,
99+ app. config . max_unpack_size ,
100+ ) ;
101+
102+ if content_length > maximums. max_upload_size {
103+ return Err ( cargo_err ( & format_args ! (
104+ "max upload size is: {}" ,
105+ maximums. max_upload_size
106+ ) ) ) ;
107+ }
108+
109+ let pkg_name = format ! ( "{}-{}" , & * metadata. name, & * metadata. vers) ;
110+ let tarball_info = process_tarball ( & pkg_name, & * tarball_bytes, maximums. max_unpack_size ) ?;
111+
112+ // `unwrap()` is safe here since `process_tarball()` validates that
113+ // we only accept manifests with a `package` section and without
114+ // inheritance.
115+ let package = tarball_info. manifest . package . unwrap ( ) ;
116+
117+ let description = package. description . map ( |it| it. as_local ( ) . unwrap ( ) ) ;
118+ let license = package. license . map ( |it| it. as_local ( ) . unwrap ( ) ) ;
119+ let license_file = package. license_file . map ( |it| it. as_local ( ) . unwrap ( ) ) ;
120+
121+ // Make sure required fields are provided
122+ fn empty ( s : Option < & String > ) -> bool {
123+ s. map_or ( true , String :: is_empty)
124+ }
125+
126+ // It can have up to three elements per below conditions.
127+ let mut missing = Vec :: with_capacity ( 3 ) ;
128+ if empty ( description. as_ref ( ) ) {
129+ missing. push ( "description" ) ;
130+ }
131+ if empty ( license. as_ref ( ) ) && empty ( license_file. as_ref ( ) ) {
132+ missing. push ( "license" ) ;
133+ }
134+ if !missing. is_empty ( ) {
135+ let message = missing_metadata_error_message ( & missing) ;
136+ return Err ( cargo_err ( & message) ) ;
137+ }
138+
113139 // Create a transaction on the database, if there are no errors,
114140 // commit the transactions to record a new or updated crate.
115141 conn. transaction ( |conn| {
@@ -136,15 +162,15 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
136162 // Persist the new crate, if it doesn't already exist
137163 let persist = NewCrate {
138164 name : & name,
139- description : metadata . description . as_deref ( ) ,
165+ description : description. as_deref ( ) ,
140166 homepage : metadata. homepage . as_deref ( ) ,
141167 documentation : metadata. documentation . as_deref ( ) ,
142168 readme : metadata. readme . as_deref ( ) ,
143169 repository : repo. as_deref ( ) ,
144170 max_upload_size : None ,
145171 } ;
146172
147- let license_file = metadata . license_file . as_deref ( ) ;
173+ let license_file = license_file. as_deref ( ) ;
148174
149175 validate_url ( persist. homepage , "homepage" ) ?;
150176 validate_url ( persist. documentation , "documentation" ) ?;
@@ -182,40 +208,17 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
182208 }
183209 }
184210
185- let content_length = tarball_bytes. len ( ) as u64 ;
186-
187- let maximums = Maximums :: new (
188- krate. max_upload_size ,
189- app. config . max_upload_size ,
190- app. config . max_unpack_size ,
191- ) ;
192-
193- if content_length > maximums. max_upload_size {
194- return Err ( cargo_err ( & format_args ! (
195- "max upload size is: {}" ,
196- maximums. max_upload_size
197- ) ) ) ;
198- }
199-
200211 // Read tarball from request
201212 let hex_cksum: String = Sha256 :: digest ( & tarball_bytes) . encode_hex ( ) ;
202213
203- let pkg_name = format ! ( "{}-{}" , krate. name, vers) ;
204- let tarball_info =
205- process_tarball ( & pkg_name, & * tarball_bytes, maximums. max_unpack_size ) ?;
206-
207- // `unwrap()` is safe here since `process_tarball()` validates that
208- // we only accept manifests with a `package` section and without
209- // inheritance.
210- let package = tarball_info. manifest . package . unwrap ( ) ;
211214 let rust_version = package. rust_version . map ( |rv| rv. as_local ( ) . unwrap ( ) ) ;
212215
213216 // Persist the new version of this crate
214217 let version = NewVersion :: new (
215218 krate. id ,
216219 vers,
217220 & features,
218- metadata . license ,
221+ license,
219222 license_file,
220223 // Downcast is okay because the file length must be less than the max upload size
221224 // to get here, and max upload sizes are way less than i32 max
0 commit comments