@@ -12,9 +12,9 @@ use libc::{c_int, c_char, c_void, ssize_t};
1212use libc;
1313use std:: c_str:: CString ;
1414use std:: c_str;
15- use std:: io:: { FileStat , IoError } ;
16- use std:: io;
1715use std:: mem;
16+ use std:: os;
17+ use std:: rt:: rtio:: { IoResult , IoError } ;
1818use std:: rt:: rtio;
1919use std:: rt:: task:: BlockedTask ;
2020
@@ -56,21 +56,23 @@ impl FsRequest {
5656 } )
5757 }
5858
59- pub fn lstat ( loop_ : & Loop , path : & CString ) -> Result < FileStat , UvError > {
59+ pub fn lstat ( loop_ : & Loop , path : & CString )
60+ -> Result < rtio:: FileStat , UvError >
61+ {
6062 execute ( |req, cb| unsafe {
6163 uvll:: uv_fs_lstat ( loop_. handle , req, path. with_ref ( |p| p) ,
6264 cb)
6365 } ) . map ( |req| req. mkstat ( ) )
6466 }
6567
66- pub fn stat ( loop_ : & Loop , path : & CString ) -> Result < FileStat , UvError > {
68+ pub fn stat ( loop_ : & Loop , path : & CString ) -> Result < rtio :: FileStat , UvError > {
6769 execute ( |req, cb| unsafe {
6870 uvll:: uv_fs_stat ( loop_. handle , req, path. with_ref ( |p| p) ,
6971 cb)
7072 } ) . map ( |req| req. mkstat ( ) )
7173 }
7274
73- pub fn fstat ( loop_ : & Loop , fd : c_int ) -> Result < FileStat , UvError > {
75+ pub fn fstat ( loop_ : & Loop , fd : c_int ) -> Result < rtio :: FileStat , UvError > {
7476 execute ( |req, cb| unsafe {
7577 uvll:: uv_fs_fstat ( loop_. handle , req, fd, cb)
7678 } ) . map ( |req| req. mkstat ( ) )
@@ -269,40 +271,30 @@ impl FsRequest {
269271 unsafe { uvll:: get_ptr_from_fs_req ( self . req ) }
270272 }
271273
272- pub fn mkstat ( & self ) -> FileStat {
274+ pub fn mkstat ( & self ) -> rtio :: FileStat {
273275 let stat = self . get_stat ( ) ;
274276 fn to_msec ( stat : uvll:: uv_timespec_t ) -> u64 {
275277 // Be sure to cast to u64 first to prevent overflowing if the tv_sec
276278 // field is a 32-bit integer.
277279 ( stat. tv_sec as u64 ) * 1000 + ( stat. tv_nsec as u64 ) / 1000000
278280 }
279- let kind = match ( stat. st_mode as c_int ) & libc:: S_IFMT {
280- libc:: S_IFREG => io:: TypeFile ,
281- libc:: S_IFDIR => io:: TypeDirectory ,
282- libc:: S_IFIFO => io:: TypeNamedPipe ,
283- libc:: S_IFBLK => io:: TypeBlockSpecial ,
284- libc:: S_IFLNK => io:: TypeSymlink ,
285- _ => io:: TypeUnknown ,
286- } ;
287- FileStat {
281+ rtio:: FileStat {
288282 size : stat. st_size as u64 ,
289- kind : kind ,
290- perm : io :: FilePermission :: from_bits_truncate ( stat. st_mode as u32 ) ,
283+ kind : stat . st_mode as u64 ,
284+ perm : stat. st_mode as u64 ,
291285 created : to_msec ( stat. st_birthtim ) ,
292286 modified : to_msec ( stat. st_mtim ) ,
293287 accessed : to_msec ( stat. st_atim ) ,
294- unstable : io:: UnstableFileStat {
295- device : stat. st_dev as u64 ,
296- inode : stat. st_ino as u64 ,
297- rdev : stat. st_rdev as u64 ,
298- nlink : stat. st_nlink as u64 ,
299- uid : stat. st_uid as u64 ,
300- gid : stat. st_gid as u64 ,
301- blksize : stat. st_blksize as u64 ,
302- blocks : stat. st_blocks as u64 ,
303- flags : stat. st_flags as u64 ,
304- gen : stat. st_gen as u64 ,
305- }
288+ device : stat. st_dev as u64 ,
289+ inode : stat. st_ino as u64 ,
290+ rdev : stat. st_rdev as u64 ,
291+ nlink : stat. st_nlink as u64 ,
292+ uid : stat. st_uid as u64 ,
293+ gid : stat. st_gid as u64 ,
294+ blksize : stat. st_blksize as u64 ,
295+ blocks : stat. st_blocks as u64 ,
296+ flags : stat. st_flags as u64 ,
297+ gen : stat. st_gen as u64 ,
306298 }
307299 }
308300}
@@ -369,29 +361,26 @@ impl FileWatcher {
369361 }
370362 }
371363
372- fn base_read ( & mut self , buf : & mut [ u8 ] , offset : i64 ) -> Result < int , IoError > {
364+ fn base_read ( & mut self , buf : & mut [ u8 ] , offset : i64 ) -> IoResult < int > {
373365 let _m = self . fire_homing_missile ( ) ;
374366 let r = FsRequest :: read ( & self . loop_ , self . fd , buf, offset) ;
375367 r. map_err ( uv_error_to_io_error)
376368 }
377- fn base_write ( & mut self , buf : & [ u8 ] , offset : i64 ) -> Result < ( ) , IoError > {
369+ fn base_write ( & mut self , buf : & [ u8 ] , offset : i64 ) -> IoResult < ( ) > {
378370 let _m = self . fire_homing_missile ( ) ;
379371 let r = FsRequest :: write ( & self . loop_ , self . fd , buf, offset) ;
380372 r. map_err ( uv_error_to_io_error)
381373 }
382- fn seek_common ( & self , pos : i64 , whence : c_int ) ->
383- Result < u64 , IoError > {
384- unsafe {
385- match libc:: lseek ( self . fd , pos as libc:: off_t , whence) {
386- -1 => {
387- Err ( IoError {
388- kind : io:: OtherIoError ,
389- desc : "Failed to lseek." ,
390- detail : None
391- } )
392- } ,
393- n => Ok ( n as u64 )
394- }
374+ fn seek_common ( & self , pos : i64 , whence : c_int ) -> IoResult < u64 > {
375+ match unsafe { libc:: lseek ( self . fd , pos as libc:: off_t , whence) } {
376+ -1 => {
377+ Err ( IoError {
378+ code : os:: errno ( ) as uint ,
379+ extra : 0 ,
380+ detail : None ,
381+ } )
382+ } ,
383+ n => Ok ( n as u64 )
395384 }
396385 }
397386}
@@ -425,47 +414,47 @@ impl Drop for FileWatcher {
425414}
426415
427416impl rtio:: RtioFileStream for FileWatcher {
428- fn read ( & mut self , buf : & mut [ u8 ] ) -> Result < int , IoError > {
417+ fn read ( & mut self , buf : & mut [ u8 ] ) -> IoResult < int > {
429418 self . base_read ( buf, -1 )
430419 }
431- fn write ( & mut self , buf : & [ u8 ] ) -> Result < ( ) , IoError > {
420+ fn write ( & mut self , buf : & [ u8 ] ) -> IoResult < ( ) > {
432421 self . base_write ( buf, -1 )
433422 }
434- fn pread ( & mut self , buf : & mut [ u8 ] , offset : u64 ) -> Result < int , IoError > {
423+ fn pread ( & mut self , buf : & mut [ u8 ] , offset : u64 ) -> IoResult < int > {
435424 self . base_read ( buf, offset as i64 )
436425 }
437- fn pwrite ( & mut self , buf : & [ u8 ] , offset : u64 ) -> Result < ( ) , IoError > {
426+ fn pwrite ( & mut self , buf : & [ u8 ] , offset : u64 ) -> IoResult < ( ) > {
438427 self . base_write ( buf, offset as i64 )
439428 }
440- fn seek ( & mut self , pos : i64 , whence : io :: SeekStyle ) -> Result < u64 , IoError > {
429+ fn seek ( & mut self , pos : i64 , whence : rtio :: SeekStyle ) -> IoResult < u64 > {
441430 use libc:: { SEEK_SET , SEEK_CUR , SEEK_END } ;
442431 let whence = match whence {
443- io :: SeekSet => SEEK_SET ,
444- io :: SeekCur => SEEK_CUR ,
445- io :: SeekEnd => SEEK_END
432+ rtio :: SeekSet => SEEK_SET ,
433+ rtio :: SeekCur => SEEK_CUR ,
434+ rtio :: SeekEnd => SEEK_END
446435 } ;
447436 self . seek_common ( pos, whence)
448437 }
449- fn tell ( & self ) -> Result < u64 , IoError > {
438+ fn tell ( & self ) -> IoResult < u64 > {
450439 use libc:: SEEK_CUR ;
451440
452441 self . seek_common ( 0 , SEEK_CUR )
453442 }
454- fn fsync ( & mut self ) -> Result < ( ) , IoError > {
443+ fn fsync ( & mut self ) -> IoResult < ( ) > {
455444 let _m = self . fire_homing_missile ( ) ;
456445 FsRequest :: fsync ( & self . loop_ , self . fd ) . map_err ( uv_error_to_io_error)
457446 }
458- fn datasync ( & mut self ) -> Result < ( ) , IoError > {
447+ fn datasync ( & mut self ) -> IoResult < ( ) > {
459448 let _m = self . fire_homing_missile ( ) ;
460449 FsRequest :: datasync ( & self . loop_ , self . fd ) . map_err ( uv_error_to_io_error)
461450 }
462- fn truncate ( & mut self , offset : i64 ) -> Result < ( ) , IoError > {
451+ fn truncate ( & mut self , offset : i64 ) -> IoResult < ( ) > {
463452 let _m = self . fire_homing_missile ( ) ;
464453 let r = FsRequest :: truncate ( & self . loop_ , self . fd , offset) ;
465454 r. map_err ( uv_error_to_io_error)
466455 }
467456
468- fn fstat ( & mut self ) -> Result < FileStat , IoError > {
457+ fn fstat ( & mut self ) -> IoResult < rtio :: FileStat > {
469458 let _m = self . fire_homing_missile ( ) ;
470459 FsRequest :: fstat ( & self . loop_ , self . fd ) . map_err ( uv_error_to_io_error)
471460 }
@@ -475,7 +464,6 @@ impl rtio::RtioFileStream for FileWatcher {
475464mod test {
476465 use libc:: c_int;
477466 use libc:: { O_CREAT , O_RDWR , O_RDONLY , S_IWUSR , S_IRUSR } ;
478- use std:: io;
479467 use std:: str;
480468 use super :: FsRequest ;
481469 use super :: super :: Loop ;
@@ -562,10 +550,6 @@ mod test {
562550 let result = FsRequest :: mkdir ( l ( ) , path, mode) ;
563551 assert ! ( result. is_ok( ) ) ;
564552
565- let result = FsRequest :: stat ( l ( ) , path) ;
566- assert ! ( result. is_ok( ) ) ;
567- assert ! ( result. unwrap( ) . kind == io:: TypeDirectory ) ;
568-
569553 let result = FsRequest :: rmdir ( l ( ) , path) ;
570554 assert ! ( result. is_ok( ) ) ;
571555
0 commit comments