@@ -19,6 +19,7 @@ use crate::models::{
1919
2020use crate :: middleware:: log_request:: RequestLogExt ;
2121use crate :: models:: token:: EndpointScope ;
22+ use crate :: models:: version:: validate_license_expr;
2223use crate :: rate_limiter:: LimitedAction ;
2324use crate :: schema:: * ;
2425use crate :: sql:: canon_crate_name;
@@ -115,7 +116,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
115116 let package = tarball_info. manifest . package . unwrap ( ) ;
116117
117118 let description = package. description . map ( |it| it. as_local ( ) . unwrap ( ) ) ;
118- let license = package. license . map ( |it| it. as_local ( ) . unwrap ( ) ) ;
119+ let mut license = package. license . map ( |it| it. as_local ( ) . unwrap ( ) ) ;
119120 let license_file = package. license_file . map ( |it| it. as_local ( ) . unwrap ( ) ) ;
120121
121122 // Make sure required fields are provided
@@ -136,6 +137,15 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
136137 return Err ( cargo_err ( & message) ) ;
137138 }
138139
140+ if let Some ( ref license) = license {
141+ validate_license_expr ( license) ?;
142+ } else if license_file. is_some ( ) {
143+ // If no license is given, but a license file is given, flag this
144+ // crate as having a nonstandard license. Note that we don't
145+ // actually do anything else with license_file currently.
146+ license = Some ( String :: from ( "non-standard" ) ) ;
147+ }
148+
139149 // Create a transaction on the database, if there are no errors,
140150 // commit the transactions to record a new or updated crate.
141151 conn. transaction ( |conn| {
@@ -170,8 +180,6 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
170180 max_upload_size : None ,
171181 } ;
172182
173- let license_file = license_file. as_deref ( ) ;
174-
175183 validate_url ( persist. homepage , "homepage" ) ?;
176184 validate_url ( persist. documentation , "documentation" ) ?;
177185 validate_url ( persist. repository , "repository" ) ?;
@@ -219,7 +227,6 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
219227 vers,
220228 & features,
221229 license,
222- license_file,
223230 // Downcast is okay because the file length must be less than the max upload size
224231 // to get here, and max upload sizes are way less than i32 max
225232 content_length as i32 ,
0 commit comments