@@ -15,6 +15,7 @@ use super::page::Page;
1515use rustc_serialize:: json:: { Json , ToJson } ;
1616use std:: collections:: BTreeMap ;
1717use iron:: headers:: { Expires , HttpDate , CacheControl , CacheDirective } ;
18+ use postgres:: Connection ;
1819use time;
1920use iron:: Handler ;
2021use utils;
@@ -260,32 +261,11 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
260261
261262 content. full = file_content;
262263 let crate_details = cexpect ! ( CrateDetails :: new( & conn, & name, & version) ) ;
263- let latest_version = latest_version ( & crate_details. versions , & version) ;
264-
265- let ( path, version) = if let Some ( version) = latest_version {
264+ let ( path, version) = if let Some ( version) = latest_version ( & crate_details. versions , & version) {
266265 req_path[ 2 ] = & version;
267- let path = if File :: from_path ( & conn, & req_path. join ( "/" ) ) . is_some ( ) {
268- req_path[ 3 ..] . join ( "/" ) // NOTE: this adds 'index.html' if it wasn't there before
269- } else { // this page doesn't exist in the latest version
270- let search_item = if * req_path. last ( ) . unwrap ( ) == "index.html" { // this is a module
271- req_path[ & req_path. len ( ) - 2 ]
272- } else { // this is an item
273- req_path. last ( ) . unwrap ( ) . split ( '.' ) . nth ( 1 )
274- . expect ( "paths should be of the form <class>.<name>.html" )
275- } ;
276- // check if req_path[3] is the platform choice or the name of the crate
277- let concat_path;
278- let crate_root = if req_path[ 3 ] != crate_details. target_name {
279- concat_path = format ! ( "{}/{}" , req_path[ 3 ] , req_path[ 4 ] ) ;
280- & concat_path
281- } else {
282- req_path[ 3 ]
283- } ;
284- format ! ( "{}/?search={}" , crate_root, search_item)
285- } ;
286- ( path, version)
266+ ( path_for_version ( & req_path, & crate_details. target_name , & conn) , version)
287267 } else {
288- ( String :: new ( ) , String :: new ( ) )
268+ Default :: default ( )
289269 } ;
290270
291271 content. crate_details = Some ( crate_details) ;
@@ -300,7 +280,27 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
300280 . to_resp ( "rustdoc" )
301281}
302282
303-
283+ fn path_for_version ( req_path : & [ & str ] , target_name : & str , conn : & Connection ) -> String {
284+ if File :: from_path ( & conn, & req_path. join ( "/" ) ) . is_some ( ) {
285+ req_path[ 3 ..] . join ( "/" ) // NOTE: this adds 'index.html' if it wasn't there before
286+ } else { // this page doesn't exist in the latest version
287+ let search_item = if * req_path. last ( ) . unwrap ( ) == "index.html" { // this is a module
288+ req_path[ req_path. len ( ) - 2 ]
289+ } else { // this is an item
290+ req_path. last ( ) . unwrap ( ) . split ( '.' ) . nth ( 1 )
291+ . expect ( "paths should be of the form <class>.<name>.html" )
292+ } ;
293+ // check if req_path[3] is the platform choice or the name of the crate
294+ let concat_path;
295+ let crate_root = if req_path[ 3 ] != target_name {
296+ concat_path = format ! ( "{}/{}" , req_path[ 3 ] , req_path[ 4 ] ) ;
297+ & concat_path
298+ } else {
299+ req_path[ 3 ]
300+ } ;
301+ format ! ( "{}/?search={}" , crate_root, search_item)
302+ }
303+ }
304304
305305pub fn badge_handler ( req : & mut Request ) -> IronResult < Response > {
306306 use iron:: headers:: ContentType ;
0 commit comments