File tree Expand file tree Collapse file tree 2 files changed +16
-15
lines changed
Expand file tree Collapse file tree 2 files changed +16
-15
lines changed Original file line number Diff line number Diff line change @@ -867,32 +867,33 @@ pub fn make_absolute(p: &Path) -> IoResult<Path> {
867867/// use std::path::Path;
868868///
869869/// let root = Path::new("/");
870- /// assert!(os::change_dir(&root));
870+ /// assert!(os::change_dir(&root).is_ok() );
871871/// println!("Successfully changed working directory to {}!", root.display());
872872/// ```
873- pub fn change_dir ( p : & Path ) -> bool {
873+ pub fn change_dir ( p : & Path ) -> IoResult < ( ) > {
874874 return chdir ( p) ;
875875
876876 #[ cfg( windows) ]
877- fn chdir ( p : & Path ) -> bool {
878- let p = match p. as_str ( ) {
879- Some ( s) => {
880- let mut p = s. utf16_units ( ) . collect :: < Vec < u16 > > ( ) ;
881- p. push ( 0 ) ;
882- p
883- }
884- None => return false ,
885- } ;
877+ fn chdir ( p : & Path ) -> IoResult < ( ) > {
878+ let mut p = p. as_str ( ) . unwrap ( ) . utf16_units ( ) . collect :: < Vec < u16 > > ( ) ;
879+ p. push ( 0 ) ;
880+
886881 unsafe {
887- libc:: SetCurrentDirectoryW ( p. as_ptr ( ) ) != ( 0 as libc:: BOOL )
882+ match libc:: SetCurrentDirectoryW ( p. as_ptr ( ) ) != ( 0 as libc:: BOOL ) {
883+ true => Ok ( ( ) ) ,
884+ false => Err ( IoError :: last_error ( ) ) ,
885+ }
888886 }
889887 }
890888
891889 #[ cfg( unix) ]
892- fn chdir ( p : & Path ) -> bool {
890+ fn chdir ( p : & Path ) -> IoResult < ( ) > {
893891 p. with_c_str ( |buf| {
894892 unsafe {
895- libc:: chdir ( buf) == ( 0 as c_int )
893+ match libc:: chdir ( buf) == ( 0 as c_int ) {
894+ true => Ok ( ( ) ) ,
895+ false => Err ( IoError :: last_error ( ) ) ,
896+ }
896897 }
897898 } )
898899 }
Original file line number Diff line number Diff line change @@ -190,7 +190,7 @@ pub fn dont_double_panic() {
190190
191191fn in_tmpdir ( f: ||) {
192192 let tmpdir = TempDir :: new ( "test" ) . ok ( ) . expect ( "can't make tmpdir" ) ;
193- assert ! ( os:: change_dir( tmpdir. path( ) ) ) ;
193+ assert ! ( os:: change_dir( tmpdir. path( ) ) . is_ok ( ) ) ;
194194
195195 f ( ) ;
196196}
You can’t perform that action at this time.
0 commit comments