File tree 2 files changed +16
-15
lines changed
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> {
867
867
/// use std::path::Path;
868
868
///
869
869
/// let root = Path::new("/");
870
- /// assert!(os::change_dir(&root));
870
+ /// assert!(os::change_dir(&root).is_ok() );
871
871
/// println!("Successfully changed working directory to {}!", root.display());
872
872
/// ```
873
- pub fn change_dir ( p : & Path ) -> bool {
873
+ pub fn change_dir ( p : & Path ) -> IoResult < ( ) > {
874
874
return chdir ( p) ;
875
875
876
876
#[ 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
+
886
881
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
+ }
888
886
}
889
887
}
890
888
891
889
#[ cfg( unix) ]
892
- fn chdir ( p : & Path ) -> bool {
890
+ fn chdir ( p : & Path ) -> IoResult < ( ) > {
893
891
p. with_c_str ( |buf| {
894
892
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
+ }
896
897
}
897
898
} )
898
899
}
Original file line number Diff line number Diff line change @@ -190,7 +190,7 @@ pub fn dont_double_panic() {
190
190
191
191
fn in_tmpdir ( f: ||) {
192
192
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 ( ) ) ;
194
194
195
195
f ( ) ;
196
196
}
You can’t perform that action at this time.
0 commit comments