Skip to content

Commit 13428d3

Browse files
committed
---
yaml --- r: 145207 b: refs/heads/try2 c: e9acdd9 h: refs/heads/master i: 145205: 2084e1b 145203: 1d6e9ed 145199: b1c1654 v: v3
1 parent 7e7eaf2 commit 13428d3

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 52840a5bbc7fa3bc4bf93dacc95d0db523812639
8+
refs/heads/try2: e9acdd93920f126d733d525d98234cd2df5706f1
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/rt/io/file.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rt::rtio::{RtioFileStream, IoFactory, IoFactoryObject};
1717
use rt::io::{io_error, read_error, EndOfFile,
1818
FileMode, FileAccess, FileStat, IoError,
1919
PathAlreadyExists, PathDoesntExist,
20-
MismatchedFileTypeForOperation};
20+
MismatchedFileTypeForOperation, ignore_io_error};
2121
use rt::local::Local;
2222
use option::{Some, None};
2323
use path::Path;
@@ -248,18 +248,6 @@ impl Seek for FileStream {
248248
}
249249
}
250250

251-
// helper for grabbing a stat and ignoring any
252-
// error.. used in Info wrappers
253-
fn suppressed_stat(cb: &fn() -> Option<FileStat>) -> Option<FileStat> {
254-
do io_error::cond.trap(|_| {
255-
// just swallow the error.. downstream users
256-
// who can make a decision based on a None result
257-
// won't care
258-
}).inside {
259-
cb()
260-
}
261-
}
262-
263251
/// Shared functionality between `FileInfo` and `DirectoryInfo`
264252
pub trait FileSystemInfo {
265253
/// Get the filesystem path that this instance points at,
@@ -277,7 +265,7 @@ pub trait FileSystemInfo {
277265
/// returns `true` if the location pointed at by the enclosing
278266
/// exists on the filesystem
279267
fn exists(&self) -> bool {
280-
match suppressed_stat(|| self.stat()) {
268+
match ignore_io_error(|| self.stat()) {
281269
Some(_) => true,
282270
None => false
283271
}
@@ -306,7 +294,7 @@ pub trait FileInfo : FileSystemInfo {
306294
/// false for paths to non-existent locations or directories or
307295
/// other non-regular files (named pipes, etc).
308296
fn is_file(&self) -> bool {
309-
match suppressed_stat(|| self.stat()) {
297+
match ignore_io_error(|| self.stat()) {
310298
Some(s) => s.is_file,
311299
None => false
312300
}
@@ -315,7 +303,7 @@ pub trait FileInfo : FileSystemInfo {
315303
/// Attempts to open a regular file for reading/writing based
316304
/// on provided inputs
317305
fn open_stream(&self, mode: FileMode, access: FileAccess) -> Option<FileStream> {
318-
match suppressed_stat(|| self.stat()) {
306+
match ignore_io_error(|| self.stat()) {
319307
Some(s) => match s.is_file {
320308
true => open(self.get_path(), mode, access),
321309
false => None
@@ -364,7 +352,7 @@ trait DirectoryInfo : FileSystemInfo {
364352
/// false for paths to non-existent locations or if the item is
365353
/// not a directory (eg files, named pipes, links, etc)
366354
fn is_dir(&self) -> bool {
367-
match suppressed_stat(|| self.stat()) {
355+
match ignore_io_error(|| self.stat()) {
368356
Some(s) => s.is_dir,
369357
None => false
370358
}
@@ -375,7 +363,7 @@ trait DirectoryInfo : FileSystemInfo {
375363
/// at that location or if some other error occurs during
376364
/// the mkdir operation
377365
fn mkdir(&self) {
378-
match suppressed_stat(|| self.stat()) {
366+
match ignore_io_error(|| self.stat()) {
379367
Some(_) => {
380368
io_error::cond.raise(IoError {
381369
kind: PathAlreadyExists,
@@ -391,7 +379,7 @@ trait DirectoryInfo : FileSystemInfo {
391379
/// the type underlying the given `DirectoryInfo`. Will fail
392380
/// if there is no directory at the given location or if
393381
fn rmdir(&self) {
394-
match suppressed_stat(|| self.stat()) {
382+
match ignore_io_error(|| self.stat()) {
395383
Some(s) => {
396384
match s.is_dir {
397385
true => rmdir(self.get_path()),

branches/try2/src/libstd/rt/io/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,18 @@ condition! {
401401
pub read_error: super::IoError -> ();
402402
}
403403

404+
/// Helper for wrapper calls where you want to
405+
/// ignore any io_errors that might be raised
406+
pub fn ignore_io_error<T>(cb: &fn() -> T) -> T {
407+
do io_error::cond.trap(|_| {
408+
// just swallow the error.. downstream users
409+
// who can make a decision based on a None result
410+
// won't care
411+
}).inside {
412+
cb()
413+
}
414+
}
415+
404416
pub trait Reader {
405417
/// Read bytes, up to the length of `buf` and place them in `buf`.
406418
/// Returns the number of bytes read. The number of bytes read my

0 commit comments

Comments
 (0)