about summary refs log tree commit diff
path: root/src/libstd/rt/uv
diff options
context:
space:
mode:
authorJeff Olson <olson.jeffery@gmail.com>2013-09-14 09:33:53 -0700
committerJeff Olson <olson.jeffery@gmail.com>2013-09-16 23:17:46 -0700
commitb49fc4cf4eb7299a08d83ed8880d1002ecef9257 (patch)
treea958f857bd3750f8fba3bcedd6e3b6dc8ce5cad7 /src/libstd/rt/uv
parent055488df1a6a4500de565ac2531d7bc42dd02f83 (diff)
downloadrust-b49fc4cf4eb7299a08d83ed8880d1002ecef9257.tar.gz
rust-b49fc4cf4eb7299a08d83ed8880d1002ecef9257.zip
std: adding file::{stat,mkdir,rmdir}, FileInfo and FileReader/FileWriter
add ignores for win32 tests on previous file io stuff...
Diffstat (limited to 'src/libstd/rt/uv')
-rw-r--r--src/libstd/rt/uv/file.rs6
-rw-r--r--src/libstd/rt/uv/uvio.rs104
-rw-r--r--src/libstd/rt/uv/uvll.rs4
3 files changed, 72 insertions, 42 deletions
diff --git a/src/libstd/rt/uv/file.rs b/src/libstd/rt/uv/file.rs
index 850b28718d0..34f87e3601e 100644
--- a/src/libstd/rt/uv/file.rs
+++ b/src/libstd/rt/uv/file.rs
@@ -183,9 +183,8 @@ impl FsRequest {
     // accessors/utility funcs
     fn sync_cleanup(self, result: c_int)
           -> Result<c_int, UvError> {
-        let loop_ = self.get_loop().native_handle();
         self.cleanup_and_delete();
-        match status_to_maybe_uv_error_with_loop(loop_,result as i32) {
+        match status_to_maybe_uv_error(result as i32) {
             Some(err) => Err(err),
             None => Ok(result)
         }
@@ -261,6 +260,8 @@ fn sync_cleanup(result: int)
     match status_to_maybe_uv_error(result as i32) {
         Some(err) => Err(err),
         None => Ok(result)
+    }
+}
 
 extern fn compl_cb(req: *uv_fs_t) {
     let mut req: FsRequest = NativeHandle::from_native_handle(req);
@@ -522,6 +523,7 @@ mod test {
                     assert!(uverr.is_none());
                     let loop_ = req.get_loop();
                     let stat = req.get_stat();
+                    naive_print(&loop_, fmt!("%?", stat));
                     assert!(stat.is_dir());
                     let rmdir_req = FsRequest::new();
                     do rmdir_req.rmdir(&loop_, &path) |req,uverr| {
diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs
index 4307c57529b..88d168c85d2 100644
--- a/src/libstd/rt/uv/uvio.rs
+++ b/src/libstd/rt/uv/uvio.rs
@@ -35,7 +35,7 @@ use unstable::sync::Exclusive;
 use path::Path;
 use super::super::io::support::PathLike;
 use libc::{lseek, off_t, O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY, O_WRONLY,
-          S_IRUSR, S_IWUSR};
+          S_IRUSR, S_IWUSR, S_IRWXU};
 use rt::io::{FileMode, FileAccess, OpenOrCreate, Open, Create,
              CreateOrTruncate, Append, Truncate, Read, Write, ReadWrite,
              FileStat};
@@ -413,6 +413,36 @@ impl UvIoFactory {
     }
 }
 
+/// Helper for a variety of simple uv_fs_* functions that
+/// have no ret val
+fn uv_fs_helper<P: PathLike>(loop_: &mut Loop, path: &P,
+                             cb: ~fn(&mut FsRequest, &mut Loop, &P,
+                                     ~fn(&FsRequest, Option<UvError>)))
+        -> Result<(), IoError> {
+    let result_cell = Cell::new_empty();
+    let result_cell_ptr: *Cell<Result<(), IoError>> = &result_cell;
+    let path_cell = Cell::new(path);
+    do task::unkillable { // FIXME(#8674)
+        let scheduler: ~Scheduler = Local::take();
+        let mut new_req = FsRequest::new();
+        do scheduler.deschedule_running_task_and_then |_, task| {
+            let task_cell = Cell::new(task);
+            let path = path_cell.take();
+            do cb(&mut new_req, loop_, path) |_, err| {
+                let res = match err {
+                    None => Ok(()),
+                    Some(err) => Err(uv_error_to_io_error(err))
+                };
+                unsafe { (*result_cell_ptr).put_back(res); }
+                let scheduler: ~Scheduler = Local::take();
+                scheduler.resume_blocked_task_immediately(task_cell.take());
+            };
+        }
+    }
+    assert!(!result_cell.is_empty());
+    return result_cell.take();
+}
+
 impl IoFactory for UvIoFactory {
     // Connect to an address and return a new stream
     // NB: This blocks the task waiting on the connection.
@@ -578,28 +608,11 @@ impl IoFactory for UvIoFactory {
     }
 
     fn fs_unlink<P: PathLike>(&mut self, path: &P) -> Result<(), IoError> {
-        let result_cell = Cell::new_empty();
-        let result_cell_ptr: *Cell<Result<(), IoError>> = &result_cell;
-        let path_cell = Cell::new(path);
-        do task::unkillable { // FIXME(#8674)
-            let scheduler: ~Scheduler = Local::take();
-            let unlink_req = FsRequest::new();
-            do scheduler.deschedule_running_task_and_then |_, task| {
-                let task_cell = Cell::new(task);
-                let path = path_cell.take();
-                do unlink_req.unlink(self.uv_loop(), path) |_, err| {
-                    let res = match err {
-                        None => Ok(()),
-                        Some(err) => Err(uv_error_to_io_error(err))
-                    };
-                    unsafe { (*result_cell_ptr).put_back(res); }
-                    let scheduler: ~Scheduler = Local::take();
-                    scheduler.resume_blocked_task_immediately(task_cell.take());
-                };
-            }
+        do uv_fs_helper(self.uv_loop(), path) |unlink_req, l, p, cb| {
+            do unlink_req.unlink(l, p) |req, err| {
+                cb(req, err)
+            };
         }
-        assert!(!result_cell.is_empty());
-        return result_cell.take();
     }
     fn fs_stat<P: PathLike>(&mut self, path: &P) -> Result<FileStat, IoError> {
         use str::StrSlice;
@@ -616,22 +629,22 @@ impl IoFactory for UvIoFactory {
                 let path_str = path.path_as_str(|p| p.to_owned());
                 do stat_req.stat(self.uv_loop(), path)
                       |req,err| {
-                    if err.is_none() {
-                        let stat = req.get_stat();
-                        let res = Ok(FileStat {
-                            path: Path(path_str),
-                            is_file: stat.is_file(),
-                            is_dir: stat.is_dir()
-                        });
-                        unsafe { (*result_cell_ptr).put_back(res); }
-                        let scheduler: ~Scheduler = Local::take();
-                        scheduler.resume_blocked_task_immediately(task_cell.take());
-                    } else {
-                        let res = Err(uv_error_to_io_error(err.unwrap()));
-                        unsafe { (*result_cell_ptr).put_back(res); }
-                        let scheduler: ~Scheduler = Local::take();
-                        scheduler.resume_blocked_task_immediately(task_cell.take());
-                    }
+                    let res = match err {
+                        None => {
+                            let stat = req.get_stat();
+                            Ok(FileStat {
+                                path: Path(path_str),
+                                is_file: stat.is_file(),
+                                is_dir: stat.is_dir()
+                            })
+                        },
+                        Some(e) => {
+                            Err(uv_error_to_io_error(e))
+                        }
+                    };
+                    unsafe { (*result_cell_ptr).put_back(res); }
+                    let scheduler: ~Scheduler = Local::take();
+                    scheduler.resume_blocked_task_immediately(task_cell.take());
                 };
             };
         };
@@ -672,6 +685,21 @@ impl IoFactory for UvIoFactory {
     //fn fs_fstat(&mut self, _fd: c_int) -> Result<FileStat, IoError> {
     //    Ok(FileStat)
     //}
+    fn fs_mkdir<P: PathLike>(&mut self, path: &P) -> Result<(), IoError> {
+        let mode = S_IRWXU as int;
+        do uv_fs_helper(self.uv_loop(), path) |mkdir_req, l, p, cb| {
+            do mkdir_req.mkdir(l, p, mode as int) |req, err| {
+                cb(req, err)
+            };
+        }
+    }
+    fn fs_rmdir<P: PathLike>(&mut self, path: &P) -> Result<(), IoError> {
+        do uv_fs_helper(self.uv_loop(), path) |rmdir_req, l, p, cb| {
+            do rmdir_req.rmdir(l, p) |req, err| {
+                cb(req, err)
+            };
+        }
+    }
 }
 
 pub struct UvTcpListener {
diff --git a/src/libstd/rt/uv/uvll.rs b/src/libstd/rt/uv/uvll.rs
index 89ee54be349..a2d1c48c3e1 100644
--- a/src/libstd/rt/uv/uvll.rs
+++ b/src/libstd/rt/uv/uvll.rs
@@ -142,10 +142,10 @@ impl uv_stat_t {
         }
     }
     pub fn is_file(&self) -> bool {
-        ((self.st_mode as c_int) & libc::S_IFMT) == libc::S_IFREG
+        ((self.st_mode) & libc::S_IFMT as libc::uint64_t) == libc::S_IFREG as libc::uint64_t
     }
     pub fn is_dir(&self) -> bool {
-        ((self.st_mode as c_int) & libc::S_IFMT) == libc::S_IFDIR
+        ((self.st_mode) & libc::S_IFMT as libc::uint64_t) == libc::S_IFDIR as libc::uint64_t
     }
 }