@@ -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
@@ -110,6 +91,51 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
110
91
app. rate_limiter
111
92
. check_rate_limit ( user. id , rate_limit_action, conn) ?;
112
93
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
+
113
139
// Create a transaction on the database, if there are no errors,
114
140
// commit the transactions to record a new or updated crate.
115
141
conn. transaction ( |conn| {
@@ -136,15 +162,15 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
136
162
// Persist the new crate, if it doesn't already exist
137
163
let persist = NewCrate {
138
164
name : & name,
139
- description : metadata . description . as_deref ( ) ,
165
+ description : description. as_deref ( ) ,
140
166
homepage : metadata. homepage . as_deref ( ) ,
141
167
documentation : metadata. documentation . as_deref ( ) ,
142
168
readme : metadata. readme . as_deref ( ) ,
143
169
repository : repo. as_deref ( ) ,
144
170
max_upload_size : None ,
145
171
} ;
146
172
147
- let license_file = metadata . license_file . as_deref ( ) ;
173
+ let license_file = license_file. as_deref ( ) ;
148
174
149
175
validate_url ( persist. homepage , "homepage" ) ?;
150
176
validate_url ( persist. documentation , "documentation" ) ?;
@@ -182,40 +208,17 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
182
208
}
183
209
}
184
210
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
-
200
211
// Read tarball from request
201
212
let hex_cksum: String = Sha256 :: digest ( & tarball_bytes) . encode_hex ( ) ;
202
213
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 ( ) ;
211
214
let rust_version = package. rust_version . map ( |rv| rv. as_local ( ) . unwrap ( ) ) ;
212
215
213
216
// Persist the new version of this crate
214
217
let version = NewVersion :: new (
215
218
krate. id ,
216
219
vers,
217
220
& features,
218
- metadata . license ,
221
+ license,
219
222
license_file,
220
223
// Downcast is okay because the file length must be less than the max upload size
221
224
// to get here, and max upload sizes are way less than i32 max
0 commit comments