@@ -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
@@ -133,6 +114,28 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
133114 // inheritance.
134115 let package = tarball_info. manifest . package . unwrap ( ) ;
135116
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+
136139 // Create a transaction on the database, if there are no errors,
137140 // commit the transactions to record a new or updated crate.
138141 conn. transaction ( |conn| {
@@ -159,15 +162,15 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
159162 // Persist the new crate, if it doesn't already exist
160163 let persist = NewCrate {
161164 name : & name,
162- description : metadata . description . as_deref ( ) ,
165+ description : description. as_deref ( ) ,
163166 homepage : metadata. homepage . as_deref ( ) ,
164167 documentation : metadata. documentation . as_deref ( ) ,
165168 readme : metadata. readme . as_deref ( ) ,
166169 repository : repo. as_deref ( ) ,
167170 max_upload_size : None ,
168171 } ;
169172
170- let license_file = metadata . license_file . as_deref ( ) ;
173+ let license_file = license_file. as_deref ( ) ;
171174
172175 validate_url ( persist. homepage , "homepage" ) ?;
173176 validate_url ( persist. documentation , "documentation" ) ?;
@@ -210,7 +213,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
210213 krate. id ,
211214 vers,
212215 & features,
213- metadata . license ,
216+ license,
214217 license_file,
215218 // Downcast is okay because the file length must be less than the max upload size
216219 // to get here, and max upload sizes are way less than i32 max
0 commit comments