@@ -56,16 +56,16 @@ fn try_help(config: &Config) -> CargoResult<bool> {
5656 Some ( man) => man,
5757 None => return Ok ( false ) ,
5858 } ;
59- write_and_spawn ( & man, "man" ) ?;
59+ write_and_spawn ( & subcommand , & man, "man" ) ?;
6060 } else {
6161 let txt = match extract_man ( & subcommand, "txt" ) {
6262 Some ( txt) => txt,
6363 None => return Ok ( false ) ,
6464 } ;
6565 if resolve_executable ( Path :: new ( "less" ) ) . is_ok ( ) {
66- write_and_spawn ( & txt, "less" ) ?;
66+ write_and_spawn ( & subcommand , & txt, "less" ) ?;
6767 } else if resolve_executable ( Path :: new ( "more" ) ) . is_ok ( ) {
68- write_and_spawn ( & txt, "more" ) ?;
68+ write_and_spawn ( & subcommand , & txt, "more" ) ?;
6969 } else {
7070 drop ( std:: io:: stdout ( ) . write_all ( & txt) ) ;
7171 }
@@ -117,13 +117,20 @@ fn extract_man(subcommand: &str, extension: &str) -> Option<Vec<u8>> {
117117
118118/// Write the contents of a man page to disk and spawn the given command to
119119/// display it.
120- fn write_and_spawn ( contents : & [ u8 ] , command : & str ) -> CargoResult < ( ) > {
121- let mut tmp = tempfile:: Builder :: new ( ) . prefix ( "cargo-man" ) . tempfile ( ) ?;
120+ fn write_and_spawn ( name : & str , contents : & [ u8 ] , command : & str ) -> CargoResult < ( ) > {
121+ let prefix = format ! ( "cargo-{}." , name) ;
122+ let mut tmp = tempfile:: Builder :: new ( ) . prefix ( & prefix) . tempfile ( ) ?;
122123 let f = tmp. as_file_mut ( ) ;
123124 f. write_all ( contents) ?;
124125 f. flush ( ) ?;
126+ let path = tmp. path ( ) ;
127+ // Use a path relative to the temp directory so that it can work on
128+ // cygwin/msys systems which don't handle windows-style paths.
129+ let mut relative_name = std:: ffi:: OsString :: from ( "./" ) ;
130+ relative_name. push ( path. file_name ( ) . unwrap ( ) ) ;
125131 let mut cmd = std:: process:: Command :: new ( command)
126- . arg ( tmp. path ( ) )
132+ . arg ( relative_name)
133+ . current_dir ( path. parent ( ) . unwrap ( ) )
127134 . spawn ( ) ?;
128135 drop ( cmd. wait ( ) ) ;
129136 Ok ( ( ) )
0 commit comments