@@ -7,7 +7,7 @@ use crate::{
7
7
crate_details:: CrateDetails , error:: Nope , file:: File , match_version, metrics,
8
8
page:: WebPage , redirect_base, MatchSemver ,
9
9
} ,
10
- Config ,
10
+ Config , Storage ,
11
11
} ;
12
12
use iron:: {
13
13
headers:: { CacheControl , CacheDirective , Expires , HttpDate } ,
@@ -104,12 +104,12 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
104
104
// this URL is actually from a crate-internal path, serve it there instead
105
105
return rustdoc_html_server_handler ( req) ;
106
106
} else {
107
- let pool = extension ! ( req, Pool ) ;
107
+ let storage = extension ! ( req, Storage ) ;
108
108
let config = extension ! ( req, Config ) ;
109
109
110
110
let path = req. url . path ( ) ;
111
111
let path = path. join ( "/" ) ;
112
- match File :: from_path ( pool . clone ( ) , & path, & config) {
112
+ match File :: from_path ( & storage , & path, & config) {
113
113
Ok ( f) => return Ok ( f. serve ( ) ) ,
114
114
Err ( ..) => return Err ( IronError :: new ( Nope :: ResourceNotFound , status:: NotFound ) ) ,
115
115
}
@@ -218,6 +218,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
218
218
let pool = extension ! ( req, Pool ) ;
219
219
let conn = pool. get ( ) ?;
220
220
let config = extension ! ( req, Config ) ;
221
+ let storage = extension ! ( req, Storage ) ;
221
222
let mut req_path = req. url . path ( ) ;
222
223
223
224
// Remove the name and version from the path
@@ -297,14 +298,14 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
297
298
}
298
299
299
300
// Attempt to load the file from the database
300
- let file = if let Ok ( file) = File :: from_path ( pool . clone ( ) , & path, & config) {
301
+ let file = if let Ok ( file) = File :: from_path ( & storage , & path, & config) {
301
302
file
302
303
} else {
303
304
// If it fails, we try again with /index.html at the end
304
305
path. push_str ( "/index.html" ) ;
305
306
req_path. push ( "index.html" ) ;
306
307
307
- File :: from_path ( pool . clone ( ) , & path, & config)
308
+ File :: from_path ( & storage , & path, & config)
308
309
. map_err ( |_| IronError :: new ( Nope :: ResourceNotFound , status:: NotFound ) ) ?
309
310
} ;
310
311
@@ -351,7 +352,7 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
351
352
"/{}/{}/{}" ,
352
353
name,
353
354
latest_version,
354
- path_for_version( & latest_path, & krate. doc_targets, pool . clone ( ) , & config)
355
+ path_for_version( & latest_path, & krate. doc_targets, & storage , & config)
355
356
)
356
357
} else {
357
358
format ! ( "/crate/{}/{}" , name, latest_version)
@@ -400,11 +401,11 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
400
401
fn path_for_version (
401
402
req_path : & [ & str ] ,
402
403
known_platforms : & [ String ] ,
403
- pool : Pool ,
404
+ storage : & Storage ,
404
405
config : & Config ,
405
406
) -> String {
406
407
// Simple case: page exists in the latest version, so just change the version number
407
- if File :: from_path ( pool , & req_path. join ( "/" ) , config) . is_ok ( ) {
408
+ if File :: from_path ( storage , & req_path. join ( "/" ) , config) . is_ok ( ) {
408
409
// NOTE: this adds 'index.html' if it wasn't there before
409
410
return req_path[ 3 ..] . join ( "/" ) ;
410
411
}
@@ -442,6 +443,7 @@ pub fn target_redirect_handler(req: &mut Request) -> IronResult<Response> {
442
443
443
444
let pool = extension ! ( req, Pool ) ;
444
445
let conn = pool. get ( ) ?;
446
+ let storage = extension ! ( req, Storage ) ;
445
447
let config = extension ! ( req, Config ) ;
446
448
let base = redirect_base ( req) ;
447
449
@@ -467,12 +469,7 @@ pub fn target_redirect_handler(req: &mut Request) -> IronResult<Response> {
467
469
file_path
468
470
} ;
469
471
470
- let path = path_for_version (
471
- & file_path,
472
- & crate_details. doc_targets ,
473
- pool. clone ( ) ,
474
- & config,
475
- ) ;
472
+ let path = path_for_version ( & file_path, & crate_details. doc_targets , & storage, & config) ;
476
473
let url = format ! (
477
474
"{base}/{name}/{version}/{path}" ,
478
475
base = base,
@@ -572,10 +569,10 @@ impl Handler for SharedResourceHandler {
572
569
let filename = path. last ( ) . unwrap ( ) ; // unwrap is fine: vector is non-empty
573
570
let suffix = filename. split ( '.' ) . last ( ) . unwrap ( ) ; // unwrap is fine: split always works
574
571
if [ "js" , "css" , "woff" , "svg" ] . contains ( & suffix) {
575
- let pool = extension ! ( req, Pool ) ;
572
+ let storage = extension ! ( req, Storage ) ;
576
573
let config = extension ! ( req, Config ) ;
577
574
578
- if let Ok ( file) = File :: from_path ( pool . clone ( ) , filename, & config) {
575
+ if let Ok ( file) = File :: from_path ( & storage , filename, & config) {
579
576
return Ok ( file. serve ( ) ) ;
580
577
}
581
578
}
0 commit comments