@@ -51,25 +51,6 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
51
51
request_log. add ( "crate_name" , & * metadata. name ) ;
52
52
request_log. add ( "crate_version" , & * metadata. vers ) ;
53
53
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
-
73
54
conduit_compat ( move || {
74
55
let conn = & mut * app. db_write ( ) ?;
75
56
@@ -133,6 +114,28 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
133
114
// inheritance.
134
115
let package = tarball_info. manifest . package . unwrap ( ) ;
135
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
+
136
139
// Create a transaction on the database, if there are no errors,
137
140
// commit the transactions to record a new or updated crate.
138
141
conn. transaction ( |conn| {
@@ -159,15 +162,15 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
159
162
// Persist the new crate, if it doesn't already exist
160
163
let persist = NewCrate {
161
164
name : & name,
162
- description : metadata . description . as_deref ( ) ,
165
+ description : description. as_deref ( ) ,
163
166
homepage : metadata. homepage . as_deref ( ) ,
164
167
documentation : metadata. documentation . as_deref ( ) ,
165
168
readme : metadata. readme . as_deref ( ) ,
166
169
repository : repo. as_deref ( ) ,
167
170
max_upload_size : None ,
168
171
} ;
169
172
170
- let license_file = metadata . license_file . as_deref ( ) ;
173
+ let license_file = license_file. as_deref ( ) ;
171
174
172
175
validate_url ( persist. homepage , "homepage" ) ?;
173
176
validate_url ( persist. documentation , "documentation" ) ?;
@@ -210,7 +213,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
210
213
krate. id ,
211
214
vers,
212
215
& features,
213
- metadata . license ,
216
+ license,
214
217
license_file,
215
218
// Downcast is okay because the file length must be less than the max upload size
216
219
// to get here, and max upload sizes are way less than i32 max
0 commit comments