@@ -12,9 +12,9 @@ use libc::{c_int, c_char, c_void, ssize_t};
12
12
use libc;
13
13
use std:: c_str:: CString ;
14
14
use std:: c_str;
15
- use std:: io:: { FileStat , IoError } ;
16
- use std:: io;
17
15
use std:: mem;
16
+ use std:: os;
17
+ use std:: rt:: rtio:: { IoResult , IoError } ;
18
18
use std:: rt:: rtio;
19
19
use std:: rt:: task:: BlockedTask ;
20
20
@@ -56,21 +56,23 @@ impl FsRequest {
56
56
} )
57
57
}
58
58
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
+ {
60
62
execute ( |req, cb| unsafe {
61
63
uvll:: uv_fs_lstat ( loop_. handle , req, path. with_ref ( |p| p) ,
62
64
cb)
63
65
} ) . map ( |req| req. mkstat ( ) )
64
66
}
65
67
66
- pub fn stat ( loop_ : & Loop , path : & CString ) -> Result < FileStat , UvError > {
68
+ pub fn stat ( loop_ : & Loop , path : & CString ) -> Result < rtio :: FileStat , UvError > {
67
69
execute ( |req, cb| unsafe {
68
70
uvll:: uv_fs_stat ( loop_. handle , req, path. with_ref ( |p| p) ,
69
71
cb)
70
72
} ) . map ( |req| req. mkstat ( ) )
71
73
}
72
74
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 > {
74
76
execute ( |req, cb| unsafe {
75
77
uvll:: uv_fs_fstat ( loop_. handle , req, fd, cb)
76
78
} ) . map ( |req| req. mkstat ( ) )
@@ -269,40 +271,30 @@ impl FsRequest {
269
271
unsafe { uvll:: get_ptr_from_fs_req ( self . req ) }
270
272
}
271
273
272
- pub fn mkstat ( & self ) -> FileStat {
274
+ pub fn mkstat ( & self ) -> rtio :: FileStat {
273
275
let stat = self . get_stat ( ) ;
274
276
fn to_msec ( stat : uvll:: uv_timespec_t ) -> u64 {
275
277
// Be sure to cast to u64 first to prevent overflowing if the tv_sec
276
278
// field is a 32-bit integer.
277
279
( stat. tv_sec as u64 ) * 1000 + ( stat. tv_nsec as u64 ) / 1000000
278
280
}
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 {
288
282
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 ,
291
285
created : to_msec ( stat. st_birthtim ) ,
292
286
modified : to_msec ( stat. st_mtim ) ,
293
287
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 ,
306
298
}
307
299
}
308
300
}
@@ -369,29 +361,26 @@ impl FileWatcher {
369
361
}
370
362
}
371
363
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 > {
373
365
let _m = self . fire_homing_missile ( ) ;
374
366
let r = FsRequest :: read ( & self . loop_ , self . fd , buf, offset) ;
375
367
r. map_err ( uv_error_to_io_error)
376
368
}
377
- fn base_write ( & mut self , buf : & [ u8 ] , offset : i64 ) -> Result < ( ) , IoError > {
369
+ fn base_write ( & mut self , buf : & [ u8 ] , offset : i64 ) -> IoResult < ( ) > {
378
370
let _m = self . fire_homing_missile ( ) ;
379
371
let r = FsRequest :: write ( & self . loop_ , self . fd , buf, offset) ;
380
372
r. map_err ( uv_error_to_io_error)
381
373
}
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 )
395
384
}
396
385
}
397
386
}
@@ -425,47 +414,47 @@ impl Drop for FileWatcher {
425
414
}
426
415
427
416
impl 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 > {
429
418
self . base_read ( buf, -1 )
430
419
}
431
- fn write ( & mut self , buf : & [ u8 ] ) -> Result < ( ) , IoError > {
420
+ fn write ( & mut self , buf : & [ u8 ] ) -> IoResult < ( ) > {
432
421
self . base_write ( buf, -1 )
433
422
}
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 > {
435
424
self . base_read ( buf, offset as i64 )
436
425
}
437
- fn pwrite ( & mut self , buf : & [ u8 ] , offset : u64 ) -> Result < ( ) , IoError > {
426
+ fn pwrite ( & mut self , buf : & [ u8 ] , offset : u64 ) -> IoResult < ( ) > {
438
427
self . base_write ( buf, offset as i64 )
439
428
}
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 > {
441
430
use libc:: { SEEK_SET , SEEK_CUR , SEEK_END } ;
442
431
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
446
435
} ;
447
436
self . seek_common ( pos, whence)
448
437
}
449
- fn tell ( & self ) -> Result < u64 , IoError > {
438
+ fn tell ( & self ) -> IoResult < u64 > {
450
439
use libc:: SEEK_CUR ;
451
440
452
441
self . seek_common ( 0 , SEEK_CUR )
453
442
}
454
- fn fsync ( & mut self ) -> Result < ( ) , IoError > {
443
+ fn fsync ( & mut self ) -> IoResult < ( ) > {
455
444
let _m = self . fire_homing_missile ( ) ;
456
445
FsRequest :: fsync ( & self . loop_ , self . fd ) . map_err ( uv_error_to_io_error)
457
446
}
458
- fn datasync ( & mut self ) -> Result < ( ) , IoError > {
447
+ fn datasync ( & mut self ) -> IoResult < ( ) > {
459
448
let _m = self . fire_homing_missile ( ) ;
460
449
FsRequest :: datasync ( & self . loop_ , self . fd ) . map_err ( uv_error_to_io_error)
461
450
}
462
- fn truncate ( & mut self , offset : i64 ) -> Result < ( ) , IoError > {
451
+ fn truncate ( & mut self , offset : i64 ) -> IoResult < ( ) > {
463
452
let _m = self . fire_homing_missile ( ) ;
464
453
let r = FsRequest :: truncate ( & self . loop_ , self . fd , offset) ;
465
454
r. map_err ( uv_error_to_io_error)
466
455
}
467
456
468
- fn fstat ( & mut self ) -> Result < FileStat , IoError > {
457
+ fn fstat ( & mut self ) -> IoResult < rtio :: FileStat > {
469
458
let _m = self . fire_homing_missile ( ) ;
470
459
FsRequest :: fstat ( & self . loop_ , self . fd ) . map_err ( uv_error_to_io_error)
471
460
}
@@ -475,7 +464,6 @@ impl rtio::RtioFileStream for FileWatcher {
475
464
mod test {
476
465
use libc:: c_int;
477
466
use libc:: { O_CREAT , O_RDWR , O_RDONLY , S_IWUSR , S_IRUSR } ;
478
- use std:: io;
479
467
use std:: str;
480
468
use super :: FsRequest ;
481
469
use super :: super :: Loop ;
@@ -562,10 +550,6 @@ mod test {
562
550
let result = FsRequest :: mkdir ( l ( ) , path, mode) ;
563
551
assert ! ( result. is_ok( ) ) ;
564
552
565
- let result = FsRequest :: stat ( l ( ) , path) ;
566
- assert ! ( result. is_ok( ) ) ;
567
- assert ! ( result. unwrap( ) . kind == io:: TypeDirectory ) ;
568
-
569
553
let result = FsRequest :: rmdir ( l ( ) , path) ;
570
554
assert ! ( result. is_ok( ) ) ;
571
555
0 commit comments