@@ -103,6 +103,7 @@ pub struct EncodableCrate {
103
103
pub description : Option < String > ,
104
104
pub homepage : Option < String > ,
105
105
pub documentation : Option < String > ,
106
+ pub license : Option < String > ,
106
107
pub repository : Option < String > ,
107
108
pub links : CrateLinks ,
108
109
pub exact_match : bool ,
@@ -132,13 +133,14 @@ pub struct NewCrate<'a> {
132
133
133
134
impl < ' a > NewCrate < ' a > {
134
135
pub fn create_or_update (
135
- self ,
136
+ mut self ,
136
137
conn : & PgConnection ,
138
+ license_file : Option < & ' a str > ,
137
139
uploader : i32 ,
138
140
) -> CargoResult < Crate > {
139
141
use diesel:: update;
140
142
141
- self . validate ( ) ?;
143
+ self . validate ( license_file ) ?;
142
144
self . ensure_name_not_reserved ( conn) ?;
143
145
144
146
conn. transaction ( || {
@@ -159,7 +161,7 @@ impl<'a> NewCrate<'a> {
159
161
} )
160
162
}
161
163
162
- fn validate ( & self ) -> CargoResult < ( ) > {
164
+ fn validate ( & mut self , license_file : Option < & ' a str > ) -> CargoResult < ( ) > {
163
165
fn validate_url ( url : Option < & str > , field : & str ) -> CargoResult < ( ) > {
164
166
let url = match url {
165
167
Some ( s) => s,
@@ -193,6 +195,24 @@ impl<'a> NewCrate<'a> {
193
195
validate_url ( self . homepage , "homepage" ) ?;
194
196
validate_url ( self . documentation , "documentation" ) ?;
195
197
validate_url ( self . repository , "repository" ) ?;
198
+ self . validate_license ( license_file) ?;
199
+ Ok ( ( ) )
200
+ }
201
+
202
+ fn validate_license ( & mut self , license_file : Option < & str > ) -> CargoResult < ( ) > {
203
+ if let Some ( ref license) = self . license {
204
+ for part in license. split ( '/' ) {
205
+ license_exprs:: validate_license_expr ( part)
206
+ . map_err ( |e| human ( & format_args ! ( "{}; see http://opensource.org/licenses \
207
+ for options, and http://spdx.org/licenses/ \
208
+ for their identifiers", e) ) ) ?;
209
+ }
210
+ } else if license_file. is_some ( ) {
211
+ // If no license is given, but a license file is given, flag this
212
+ // crate as having a nonstandard license. Note that we don't
213
+ // actually do anything else with license_file currently.
214
+ self . license = Some ( "non-standard" ) ;
215
+ }
196
216
Ok ( ( ) )
197
217
}
198
218
@@ -480,6 +500,7 @@ impl Crate {
480
500
homepage,
481
501
documentation,
482
502
repository,
503
+ license,
483
504
..
484
505
} = self ;
485
506
let versions_link = match versions {
@@ -505,6 +526,7 @@ impl Crate {
505
526
exact_match : exact_match,
506
527
description : description,
507
528
repository : repository,
529
+ license : license,
508
530
links : CrateLinks {
509
531
version_downloads : format ! ( "/api/v1/crates/{}/downloads" , name) ,
510
532
versions : versions_link,
@@ -1059,7 +1081,7 @@ pub fn new(req: &mut Request) -> CargoResult<Response> {
1059
1081
} ;
1060
1082
1061
1083
let license_file = new_crate. license_file . as_ref ( ) . map ( |s| & * * s) ;
1062
- let krate = persist. create_or_update ( & conn, user. id ) ?;
1084
+ let krate = persist. create_or_update ( & conn, license_file , user. id ) ?;
1063
1085
1064
1086
let owners = krate. owners ( & conn) ?;
1065
1087
if rights ( req. app ( ) , & owners, & user) ? < Rights :: Publish {
0 commit comments