1
1
2
- use { DocBuilderError , ChrootBuilderResult } ;
2
+ use ChrootBuilderResult ;
3
3
use utils:: source_path;
4
4
use regex:: Regex ;
5
5
@@ -16,6 +16,8 @@ use semver;
16
16
use postgres:: Connection ;
17
17
use time;
18
18
19
+ use errors:: * ;
20
+
19
21
20
22
21
23
/// Adds a package into database.
@@ -26,7 +28,7 @@ pub fn add_package_into_database(conn: &Connection,
26
28
res : & ChrootBuilderResult ,
27
29
files : Option < Json > ,
28
30
doc_targets : Vec < String > )
29
- -> Result < i32 , DocBuilderError > {
31
+ -> Result < i32 > {
30
32
debug ! ( "Adding package into database" ) ;
31
33
let crate_id = try!( initialize_package_in_database ( & conn, & pkg) ) ;
32
34
let dependencies = convert_dependencies ( & pkg) ;
@@ -154,7 +156,7 @@ pub fn add_package_into_database(conn: &Connection,
154
156
pub fn add_build_into_database ( conn : & Connection ,
155
157
release_id : & i32 ,
156
158
res : & ChrootBuilderResult )
157
- -> Result < i32 , DocBuilderError > {
159
+ -> Result < i32 > {
158
160
debug ! ( "Adding build into database" ) ;
159
161
let mut rows = try!( conn. query ( "SELECT id FROM builds WHERE rid = $1 AND rustc_version = $2" ,
160
162
& [ release_id, & res. rustc_version ] ) ) ;
@@ -184,7 +186,7 @@ pub fn add_build_into_database(conn: &Connection,
184
186
185
187
fn initialize_package_in_database ( conn : & Connection ,
186
188
pkg : & Package )
187
- -> Result < i32 , DocBuilderError > {
189
+ -> Result < i32 > {
188
190
let mut rows = try!( conn. query ( "SELECT id FROM crates WHERE name = $1" ,
189
191
& [ & pkg. manifest ( ) . name ( ) ] ) ) ;
190
192
// insert crate into database if it is not exists
@@ -210,10 +212,10 @@ fn convert_dependencies(pkg: &Package) -> Vec<(String, String)> {
210
212
211
213
212
214
/// Reads readme if there is any read defined in Cargo.toml of a Package
213
- fn get_readme ( pkg : & Package ) -> Result < Option < String > , DocBuilderError > {
215
+ fn get_readme ( pkg : & Package ) -> Result < Option < String > > {
214
216
if pkg. manifest ( ) . metadata ( ) . readme . is_some ( ) {
215
217
let readme_path = PathBuf :: from ( try!( source_path ( & pkg)
216
- . ok_or ( DocBuilderError :: FileNotFound ) ) )
218
+ . ok_or ( "File not found" ) ) )
217
219
. join ( pkg. manifest ( ) . metadata ( ) . readme . clone ( ) . unwrap ( ) ) ;
218
220
let mut reader = try!( fs:: File :: open ( readme_path) . map ( |f| BufReader :: new ( f) ) ) ;
219
221
let mut readme = String :: new ( ) ;
@@ -225,19 +227,19 @@ fn get_readme(pkg: &Package) -> Result<Option<String>, DocBuilderError> {
225
227
}
226
228
227
229
228
- fn get_rustdoc ( pkg : & Package ) -> Result < Option < String > , DocBuilderError > {
230
+ fn get_rustdoc ( pkg : & Package ) -> Result < Option < String > > {
229
231
if pkg. manifest ( ) . targets ( ) [ 0 ] . src_path ( ) . is_absolute ( ) {
230
232
read_rust_doc ( pkg. manifest ( ) . targets ( ) [ 0 ] . src_path ( ) )
231
233
} else {
232
- let mut path = PathBuf :: from ( try!( source_path ( & pkg) . ok_or ( DocBuilderError :: FileNotFound ) ) ) ;
234
+ let mut path = PathBuf :: from ( try!( source_path ( & pkg) . ok_or ( "File not found" ) ) ) ;
233
235
path. push ( pkg. manifest ( ) . targets ( ) [ 0 ] . src_path ( ) ) ;
234
236
read_rust_doc ( path. as_path ( ) )
235
237
}
236
238
}
237
239
238
240
239
241
/// Reads rustdoc from library
240
- fn read_rust_doc ( file_path : & Path ) -> Result < Option < String > , DocBuilderError > {
242
+ fn read_rust_doc ( file_path : & Path ) -> Result < Option < String > > {
241
243
let reader = try!( fs:: File :: open ( file_path) . map ( |f| BufReader :: new ( f) ) ) ;
242
244
let mut rustdoc = String :: new ( ) ;
243
245
@@ -263,7 +265,7 @@ fn read_rust_doc(file_path: &Path) -> Result<Option<String>, DocBuilderError> {
263
265
/// Get release_time, yanked and downloads from crates.io
264
266
fn get_release_time_yanked_downloads
265
267
( pkg : & Package )
266
- -> Result < ( Option < time:: Timespec > , Option < bool > , Option < i32 > ) , DocBuilderError > {
268
+ -> Result < ( Option < time:: Timespec > , Option < bool > , Option < i32 > ) > {
267
269
let url = format ! ( "https://crates.io/api/v1/crates/{}/versions" ,
268
270
pkg. manifest( ) . name( ) ) ;
269
271
// FIXME: There is probably better way to do this
@@ -276,30 +278,30 @@ fn get_release_time_yanked_downloads
276
278
let versions = try!( json. as_object ( )
277
279
. and_then ( |o| o. get ( "versions" ) )
278
280
. and_then ( |v| v. as_array ( ) )
279
- . ok_or ( DocBuilderError :: JsonNotObject ) ) ;
281
+ . ok_or ( "Not a JSON object" ) ) ;
280
282
281
283
let ( mut release_time, mut yanked, mut downloads) = ( None , None , None ) ;
282
284
283
285
for version in versions {
284
- let version = try!( version. as_object ( ) . ok_or ( DocBuilderError :: JsonNotObject ) ) ;
286
+ let version = try!( version. as_object ( ) . ok_or ( "Not a JSON object" ) ) ;
285
287
let version_num = try!( version. get ( "num" )
286
288
. and_then ( |v| v. as_string ( ) )
287
- . ok_or ( DocBuilderError :: JsonNotObject ) ) ;
289
+ . ok_or ( "Not a JSON object" ) ) ;
288
290
289
291
if & semver:: Version :: parse ( version_num) . unwrap ( ) == pkg. manifest ( ) . version ( ) {
290
292
let release_time_raw = try!( version. get ( "created_at" )
291
293
. and_then ( |c| c. as_string ( ) )
292
- . ok_or ( DocBuilderError :: JsonNotObject ) ) ;
294
+ . ok_or ( "Not a JSON object" ) ) ;
293
295
release_time = Some ( time:: strptime ( release_time_raw, "%Y-%m-%dT%H:%M:%S" )
294
296
. unwrap ( )
295
297
. to_timespec ( ) ) ;
296
298
297
299
yanked = Some ( try!( version. get ( "yanked" )
298
300
. and_then ( |c| c. as_boolean ( ) )
299
- . ok_or ( DocBuilderError :: JsonNotObject ) ) ) ;
301
+ . ok_or ( "Not a JSON object" ) ) ) ;
300
302
301
303
downloads = Some ( try!( version. get ( "downloads" ) . and_then ( |c| c. as_i64 ( ) )
302
- . ok_or ( DocBuilderError :: JsonNotObject ) ) as i32 ) ;
304
+ . ok_or ( "Not a JSON object" ) ) as i32 ) ;
303
305
304
306
break ;
305
307
}
@@ -313,7 +315,7 @@ fn get_release_time_yanked_downloads
313
315
fn add_keywords_into_database ( conn : & Connection ,
314
316
pkg : & Package ,
315
317
release_id : & i32 )
316
- -> Result < ( ) , DocBuilderError > {
318
+ -> Result < ( ) > {
317
319
for keyword in & pkg. manifest ( ) . metadata ( ) . keywords {
318
320
let slug = slugify ( & keyword) ;
319
321
let keyword_id: i32 = {
@@ -341,7 +343,7 @@ fn add_keywords_into_database(conn: &Connection,
341
343
fn add_authors_into_database ( conn : & Connection ,
342
344
pkg : & Package ,
343
345
release_id : & i32 )
344
- -> Result < ( ) , DocBuilderError > {
346
+ -> Result < ( ) > {
345
347
346
348
let author_capture_re = Regex :: new ( "^([^><]+)<*(.*?)>*$" ) . unwrap ( ) ;
347
349
for author in & pkg. manifest ( ) . metadata ( ) . authors {
@@ -378,7 +380,7 @@ fn add_authors_into_database(conn: &Connection,
378
380
fn add_owners_into_database ( conn : & Connection ,
379
381
pkg : & Package ,
380
382
crate_id : & i32 )
381
- -> Result < ( ) , DocBuilderError > {
383
+ -> Result < ( ) > {
382
384
// owners available in: https://crates.io/api/v1/crates/rand/owners
383
385
let owners_url = format ! ( "https://crates.io/api/v1/crates/{}/owners" ,
384
386
& pkg. manifest( ) . name( ) ) ;
0 commit comments