@@ -54,7 +54,7 @@ use super::{SeekStyle, Read, Write, Open, IoError, Truncate,
54
54
use rt:: rtio:: { RtioFileStream , IoFactory , LocalIo } ;
55
55
use io;
56
56
use option:: { Some , None , Option } ;
57
- use result:: { Ok , Err , Result } ;
57
+ use result:: { Ok , Err } ;
58
58
use path;
59
59
use path:: { Path , GenericPath } ;
60
60
use vec:: { OwnedVector , ImmutableVector } ;
@@ -75,17 +75,6 @@ pub struct File {
75
75
priv last_nread : int ,
76
76
}
77
77
78
- fn io_raise < T > ( f: |io: & mut IoFactory | -> Result < T , IoError > ) -> Option < T > {
79
- let mut io = LocalIo :: borrow ( ) ;
80
- match f ( io. get ( ) ) {
81
- Ok ( t) => Some ( t) ,
82
- Err ( ioerr) => {
83
- io_error:: cond. raise ( ioerr) ;
84
- None
85
- }
86
- }
87
- }
88
-
89
78
impl File {
90
79
/// Open a file at `path` in the mode specified by the `mode` and `access`
91
80
/// arguments
@@ -131,18 +120,15 @@ impl File {
131
120
pub fn open_mode ( path : & Path ,
132
121
mode : FileMode ,
133
122
access : FileAccess ) -> Option < File > {
134
- let mut io = LocalIo :: borrow ( ) ;
135
- match io. get ( ) . fs_open ( & path. to_c_str ( ) , mode, access) {
136
- Ok ( fd) => Some ( File {
137
- path : path. clone ( ) ,
138
- fd : fd,
139
- last_nread : -1
140
- } ) ,
141
- Err ( ioerr) => {
142
- io_error:: cond. raise ( ioerr) ;
143
- None
144
- }
145
- }
123
+ LocalIo :: maybe_raise ( |io| {
124
+ io. fs_open ( & path. to_c_str ( ) , mode, access) . map ( |fd| {
125
+ File {
126
+ path : path. clone ( ) ,
127
+ fd : fd,
128
+ last_nread : -1
129
+ }
130
+ } )
131
+ } )
146
132
}
147
133
148
134
/// Attempts to open a file in read-only mode. This function is equivalent to
@@ -242,7 +228,7 @@ impl File {
242
228
/// directory, the user lacks permissions to remove the file, or if some
243
229
/// other filesystem-level error occurs.
244
230
pub fn unlink ( path : & Path ) {
245
- io_raise ( |io| io. fs_unlink ( & path. to_c_str ( ) ) ) ;
231
+ LocalIo :: maybe_raise ( |io| io. fs_unlink ( & path. to_c_str ( ) ) ) ;
246
232
}
247
233
248
234
/// Given a path, query the file system to get information about a file,
@@ -270,7 +256,9 @@ pub fn unlink(path: &Path) {
270
256
/// requisite permissions to perform a `stat` call on the given path or if
271
257
/// there is no entry in the filesystem at the provided path.
272
258
pub fn stat ( path : & Path ) -> FileStat {
273
- io_raise ( |io| io. fs_stat ( & path. to_c_str ( ) ) ) . unwrap_or_else ( dummystat)
259
+ LocalIo :: maybe_raise ( |io| {
260
+ io. fs_stat ( & path. to_c_str ( ) )
261
+ } ) . unwrap_or_else ( dummystat)
274
262
}
275
263
276
264
fn dummystat ( ) -> FileStat {
@@ -306,7 +294,9 @@ fn dummystat() -> FileStat {
306
294
///
307
295
/// See `stat`
308
296
pub fn lstat ( path : & Path ) -> FileStat {
309
- io_raise ( |io| io. fs_lstat ( & path. to_c_str ( ) ) ) . unwrap_or_else ( dummystat)
297
+ LocalIo :: maybe_raise ( |io| {
298
+ io. fs_lstat ( & path. to_c_str ( ) )
299
+ } ) . unwrap_or_else ( dummystat)
310
300
}
311
301
312
302
/// Rename a file or directory to a new name.
@@ -324,7 +314,7 @@ pub fn lstat(path: &Path) -> FileStat {
324
314
/// the process lacks permissions to view the contents, or if some other
325
315
/// intermittent I/O error occurs.
326
316
pub fn rename ( from : & Path , to : & Path ) {
327
- io_raise ( |io| io. fs_rename ( & from. to_c_str ( ) , & to. to_c_str ( ) ) ) ;
317
+ LocalIo :: maybe_raise ( |io| io. fs_rename ( & from. to_c_str ( ) , & to. to_c_str ( ) ) ) ;
328
318
}
329
319
330
320
/// Copies the contents of one file to another. This function will also
@@ -395,7 +385,7 @@ pub fn copy(from: &Path, to: &Path) {
395
385
/// condition. Some possible error situations are not having the permission to
396
386
/// change the attributes of a file or the file not existing.
397
387
pub fn chmod ( path : & Path , mode : io:: FilePermission ) {
398
- io_raise ( |io| io. fs_chmod ( & path. to_c_str ( ) , mode) ) ;
388
+ LocalIo :: maybe_raise ( |io| io. fs_chmod ( & path. to_c_str ( ) , mode) ) ;
399
389
}
400
390
401
391
/// Change the user and group owners of a file at the specified path.
@@ -404,7 +394,7 @@ pub fn chmod(path: &Path, mode: io::FilePermission) {
404
394
///
405
395
/// This function will raise on the `io_error` condition on failure.
406
396
pub fn chown ( path : & Path , uid : int , gid : int ) {
407
- io_raise ( |io| io. fs_chown ( & path. to_c_str ( ) , uid, gid) ) ;
397
+ LocalIo :: maybe_raise ( |io| io. fs_chown ( & path. to_c_str ( ) , uid, gid) ) ;
408
398
}
409
399
410
400
/// Creates a new hard link on the filesystem. The `dst` path will be a
@@ -415,7 +405,7 @@ pub fn chown(path: &Path, uid: int, gid: int) {
415
405
///
416
406
/// This function will raise on the `io_error` condition on failure.
417
407
pub fn link ( src : & Path , dst : & Path ) {
418
- io_raise ( |io| io. fs_link ( & src. to_c_str ( ) , & dst. to_c_str ( ) ) ) ;
408
+ LocalIo :: maybe_raise ( |io| io. fs_link ( & src. to_c_str ( ) , & dst. to_c_str ( ) ) ) ;
419
409
}
420
410
421
411
/// Creates a new symbolic link on the filesystem. The `dst` path will be a
@@ -425,7 +415,7 @@ pub fn link(src: &Path, dst: &Path) {
425
415
///
426
416
/// This function will raise on the `io_error` condition on failure.
427
417
pub fn symlink ( src : & Path , dst : & Path ) {
428
- io_raise ( |io| io. fs_symlink ( & src. to_c_str ( ) , & dst. to_c_str ( ) ) ) ;
418
+ LocalIo :: maybe_raise ( |io| io. fs_symlink ( & src. to_c_str ( ) , & dst. to_c_str ( ) ) ) ;
429
419
}
430
420
431
421
/// Reads a symlink, returning the file that the symlink points to.
@@ -436,7 +426,7 @@ pub fn symlink(src: &Path, dst: &Path) {
436
426
/// conditions include reading a file that does not exist or reading a file
437
427
/// which is not a symlink.
438
428
pub fn readlink ( path : & Path ) -> Option < Path > {
439
- io_raise ( |io| io. fs_readlink ( & path. to_c_str ( ) ) )
429
+ LocalIo :: maybe_raise ( |io| io. fs_readlink ( & path. to_c_str ( ) ) )
440
430
}
441
431
442
432
/// Create a new, empty directory at the provided path
@@ -456,7 +446,7 @@ pub fn readlink(path: &Path) -> Option<Path> {
456
446
/// to make a new directory at the provided path, or if the directory already
457
447
/// exists.
458
448
pub fn mkdir ( path : & Path , mode : FilePermission ) {
459
- io_raise ( |io| io. fs_mkdir ( & path. to_c_str ( ) , mode) ) ;
449
+ LocalIo :: maybe_raise ( |io| io. fs_mkdir ( & path. to_c_str ( ) , mode) ) ;
460
450
}
461
451
462
452
/// Remove an existing, empty directory
@@ -475,7 +465,7 @@ pub fn mkdir(path: &Path, mode: FilePermission) {
475
465
/// to remove the directory at the provided path, or if the directory isn't
476
466
/// empty.
477
467
pub fn rmdir ( path : & Path ) {
478
- io_raise ( |io| io. fs_rmdir ( & path. to_c_str ( ) ) ) ;
468
+ LocalIo :: maybe_raise ( |io| io. fs_rmdir ( & path. to_c_str ( ) ) ) ;
479
469
}
480
470
481
471
/// Retrieve a vector containing all entries within a provided directory
@@ -502,7 +492,9 @@ pub fn rmdir(path: &Path) {
502
492
/// the process lacks permissions to view the contents or if the `path` points
503
493
/// at a non-directory file
504
494
pub fn readdir ( path : & Path ) -> ~[ Path ] {
505
- io_raise ( |io| io. fs_readdir ( & path. to_c_str ( ) , 0 ) ) . unwrap_or_else ( || ~[ ] )
495
+ LocalIo :: maybe_raise ( |io| {
496
+ io. fs_readdir ( & path. to_c_str ( ) , 0 )
497
+ } ) . unwrap_or_else ( || ~[ ] )
506
498
}
507
499
508
500
/// Returns an iterator which will recursively walk the directory structure
@@ -583,7 +575,7 @@ pub fn rmdir_recursive(path: &Path) {
583
575
/// happens.
584
576
// FIXME(#10301) these arguments should not be u64
585
577
pub fn change_file_times ( path : & Path , atime : u64 , mtime : u64 ) {
586
- io_raise ( |io| io. fs_utime ( & path. to_c_str ( ) , atime, mtime) ) ;
578
+ LocalIo :: maybe_raise ( |io| io. fs_utime ( & path. to_c_str ( ) , atime, mtime) ) ;
587
579
}
588
580
589
581
impl Reader for File {
0 commit comments