@@ -38,6 +38,7 @@ pub struct Crate {
38
38
pub description : Option < String > ,
39
39
pub homepage : Option < String > ,
40
40
pub documentation : Option < String > ,
41
+ pub readme : Option < String > ,
41
42
}
42
43
43
44
#[ deriving( Encodable , Decodable ) ]
@@ -80,10 +81,12 @@ impl Crate {
80
81
user_id : i32 ,
81
82
description : & Option < String > ,
82
83
homepage : & Option < String > ,
83
- documentation : & Option < String > ) -> CargoResult < Crate > {
84
+ documentation : & Option < String > ,
85
+ readme : & Option < String > ) -> CargoResult < Crate > {
84
86
let description = description. as_ref ( ) . map ( |s| s. as_slice ( ) ) ;
85
87
let homepage = homepage. as_ref ( ) . map ( |s| s. as_slice ( ) ) ;
86
88
let documentation = documentation. as_ref ( ) . map ( |s| s. as_slice ( ) ) ;
89
+ let readme = readme. as_ref ( ) . map ( |s| s. as_slice ( ) ) ;
87
90
try!( validate_url ( homepage) ) ;
88
91
try!( validate_url ( documentation) ) ;
89
92
@@ -92,25 +95,28 @@ impl Crate {
92
95
SET documentation = $1,
93
96
homepage = $2,
94
97
description = $3
95
- WHERE name = $4
98
+ readme = $4
99
+ WHERE name = $5
96
100
RETURNING *" ) ) ;
97
101
let mut rows = try!( stmt. query ( & [ & documentation, & homepage,
98
- & description, & name as & ToSql ] ) ) ;
102
+ & description, & name as & ToSql ,
103
+ & readme] ) ) ;
99
104
match rows. next ( ) {
100
105
Some ( row) => return Ok ( Model :: from_row ( & row) ) ,
101
106
None => { }
102
107
}
103
108
let stmt = try!( conn. prepare ( "INSERT INTO crates
104
109
(name, user_id, created_at,
105
110
updated_at, downloads, max_version,
106
- description, homepage, documentation)
111
+ description, homepage, documentation,
112
+ readme)
107
113
VALUES ($1, $2, $3, $3, 0, '0.0.0',
108
- $4, $5, $6)
114
+ $4, $5, $6, &7 )
109
115
RETURNING *" ) ) ;
110
116
let now = :: now ( ) ;
111
117
let mut rows = try!( stmt. query ( & [ & name as & ToSql , & user_id, & now,
112
118
& description, & homepage,
113
- & documentation] ) ) ;
119
+ & documentation, & readme ] ) ) ;
114
120
let ret: Crate = Model :: from_row ( & try!( rows. next ( ) . require ( || {
115
121
internal ( "no crate returned" )
116
122
} ) ) ) ;
@@ -253,6 +259,7 @@ impl Model for Crate {
253
259
description : row. get ( "description" ) ,
254
260
documentation : row. get ( "documentation" ) ,
255
261
homepage : row. get ( "homepage" ) ,
262
+ readme : row. get ( "readme" ) ,
256
263
max_version : semver:: Version :: parse ( max. as_slice ( ) ) . unwrap ( ) ,
257
264
}
258
265
}
@@ -432,7 +439,8 @@ pub fn new(req: &mut Request) -> CargoResult<Response> {
432
439
let mut krate = try!( Crate :: find_or_insert ( try!( req. tx ( ) ) , name, user. id ,
433
440
& new_crate. description ,
434
441
& new_crate. homepage ,
435
- & new_crate. documentation ) ) ;
442
+ & new_crate. documentation ,
443
+ & new_crate. readme ) ) ;
436
444
if krate. user_id != user. id {
437
445
let owners = try!( krate. owners ( try!( req. tx ( ) ) ) ) ;
438
446
if !owners. iter ( ) . any ( |o| o. id == user. id ) {
@@ -721,7 +729,7 @@ fn modify_owners(req: &mut Request, add: bool) -> CargoResult<Response> {
721
729
}
722
730
723
731
#[ deriving( Decodable ) ] struct Request { users : Vec < String > }
724
- let request: Request = try!( json:: decode ( body. as_slice ( ) ) . map_err ( |e | {
732
+ let request: Request = try!( json:: decode ( body. as_slice ( ) ) . map_err ( |_ | {
725
733
human ( "invalid json request" )
726
734
} ) ) ;
727
735
0 commit comments