@@ -52,13 +52,15 @@ fs::unlink(&path);
52
52
use c_str:: ToCStr ;
53
53
use clone:: Clone ;
54
54
use collections:: Collection ;
55
+ use io:: standard_error;
55
56
use io:: { FilePermission , Write , UnstableFileStat , Open , FileAccess , FileMode } ;
56
57
use io:: { IoResult , IoError , FileStat , SeekStyle , Seek , Writer , Reader } ;
57
58
use io:: { Read , Truncate , SeekCur , SeekSet , ReadWrite , SeekEnd , Append } ;
58
- use io;
59
+ use io:: UpdateIoError ;
59
60
use io;
60
61
use iter:: Iterator ;
61
62
use kinds:: Send ;
63
+ use libc;
62
64
use option:: { Some , None , Option } ;
63
65
use owned:: Box ;
64
66
use path:: { Path , GenericPath } ;
@@ -67,6 +69,7 @@ use result::{Err, Ok};
67
69
use rt:: rtio:: LocalIo ;
68
70
use rt:: rtio;
69
71
use slice:: ImmutableVector ;
72
+ use string:: String ;
70
73
use vec:: Vec ;
71
74
72
75
/// Unconstrained file access type that exposes read and write operations
@@ -128,18 +131,18 @@ impl File {
128
131
pub fn open_mode ( path : & Path ,
129
132
mode : FileMode ,
130
133
access : FileAccess ) -> IoResult < File > {
131
- let mode = match mode {
134
+ let rtio_mode = match mode {
132
135
Open => rtio:: Open ,
133
136
Append => rtio:: Append ,
134
137
Truncate => rtio:: Truncate ,
135
138
} ;
136
- let access = match access {
139
+ let rtio_access = match access {
137
140
Read => rtio:: Read ,
138
141
Write => rtio:: Write ,
139
142
ReadWrite => rtio:: ReadWrite ,
140
143
} ;
141
144
let err = LocalIo :: maybe_raise ( |io| {
142
- io. fs_open ( & path. to_c_str ( ) , mode , access ) . map ( |fd| {
145
+ io. fs_open ( & path. to_c_str ( ) , rtio_mode , rtio_access ) . map ( |fd| {
143
146
File {
144
147
path : path. clone ( ) ,
145
148
fd : fd,
@@ -775,7 +778,8 @@ impl Reader for File {
775
778
e, file. path. display( ) ) )
776
779
}
777
780
778
- let result: IoResult < int > = update_err ( self . fd . read ( buf) , self ) ;
781
+ let result = update_err ( self . fd . read ( buf)
782
+ . map_err ( IoError :: from_rtio_error) , self ) ;
779
783
780
784
match result {
781
785
Ok ( read) => {
@@ -785,14 +789,14 @@ impl Reader for File {
785
789
_ => Ok ( read as uint )
786
790
}
787
791
} ,
788
- Err ( e) => Err ( IoError :: from_rtio_error ( e ) ) ,
792
+ Err ( e) => Err ( e )
789
793
}
790
794
}
791
795
}
792
796
793
797
impl Writer for File {
794
798
fn write ( & mut self , buf : & [ u8 ] ) -> IoResult < ( ) > {
795
- let err = self . fd . write ( buf) . map_err ( IoError :: from_rtio_error)
799
+ let err = self . fd . write ( buf) . map_err ( IoError :: from_rtio_error) ;
796
800
err. update_err ( "couldn't write to file" ,
797
801
|e| format ! ( "{}; path={}" , e, self . path. display( ) ) )
798
802
}
0 commit comments