about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustuv/file.rs15
-rw-r--r--src/librustuv/uvio.rs14
-rw-r--r--src/librustuv/uvll.rs8
-rw-r--r--src/libstd/rt/rtio.rs3
-rw-r--r--src/rt/rust_uv.cpp5
5 files changed, 41 insertions, 4 deletions
diff --git a/src/librustuv/file.rs b/src/librustuv/file.rs
index 575226f7902..2303721986c 100644
--- a/src/librustuv/file.rs
+++ b/src/librustuv/file.rs
@@ -206,6 +206,21 @@ impl FsRequest {
         assert_eq!(ret, 0);
     }
 
+    pub fn rename(self, loop_: &Loop, path: &CString, to: &CString, cb: FsCallback) {
+        let complete_cb_ptr = {
+            let mut me = self;
+            me.req_boilerplate(Some(cb))
+        };
+        let ret = unsafe {
+            uvll::fs_rename(loop_.native_handle(),
+                            self.native_handle(),
+                            path.with_ref(|p| p),
+                            to.with_ref(|p| p),
+                            complete_cb_ptr)
+        };
+        assert_eq!(ret, 0);
+    }
+
     pub fn readdir(self, loop_: &Loop, path: &CString,
                    flags: c_int, cb: FsCallback) {
         let complete_cb_ptr = {
diff --git a/src/librustuv/uvio.rs b/src/librustuv/uvio.rs
index c34d20ed4f5..7ecb51bb0d6 100644
--- a/src/librustuv/uvio.rs
+++ b/src/librustuv/uvio.rs
@@ -699,10 +699,9 @@ impl IoFactory for UvIoFactory {
         assert!(!result_cell.is_empty());
         return result_cell.take();
     }
-    fn fs_mkdir(&mut self, path: &CString) -> Result<(), IoError> {
-        let mode = S_IRWXU as int;
+    fn fs_mkdir(&mut self, path: &CString, mode: int) -> Result<(), IoError> {
         do uv_fs_helper(self.uv_loop(), path) |mkdir_req, l, p, cb| {
-            do mkdir_req.mkdir(l, p, mode as int) |req, err| {
+            do mkdir_req.mkdir(l, p, mode) |req, err| {
                 cb(req, err)
             };
         }
@@ -714,6 +713,15 @@ impl IoFactory for UvIoFactory {
             };
         }
     }
+    fn fs_rename(&mut self, path: &CString, to: &CString) -> Result<(), IoError> {
+        let to = to.with_ref(|p| p);
+        do uv_fs_helper(self.uv_loop(), path) |rename_req, l, p, cb| {
+            let to = unsafe { CString::new(to, false) };
+            do rename_req.rename(l, p, &to) |req, err| {
+                cb(req, err)
+            };
+        }
+    }
     fn fs_readdir(&mut self, path: &CString, flags: c_int) ->
         Result<~[Path], IoError> {
         use str::StrSlice;
diff --git a/src/librustuv/uvll.rs b/src/librustuv/uvll.rs
index 9e86ab11286..9f26f9506a0 100644
--- a/src/librustuv/uvll.rs
+++ b/src/librustuv/uvll.rs
@@ -807,6 +807,12 @@ pub unsafe fn fs_rmdir(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
 
     rust_uv_fs_rmdir(loop_ptr, req, path, cb)
 }
+pub unsafe fn fs_rename(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
+                        to: *c_char, cb: *u8) -> c_int {
+    #[fixed_stack_segment]; #[inline(never)];
+
+    rust_uv_fs_rename(loop_ptr, req, path, to, cb)
+}
 pub unsafe fn fs_readdir(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
                 flags: c_int, cb: *u8) -> c_int {
     #[fixed_stack_segment]; #[inline(never)];
@@ -1107,6 +1113,8 @@ extern {
                         mode: c_int, cb: *u8) -> c_int;
     fn rust_uv_fs_rmdir(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char,
                         cb: *u8) -> c_int;
+    fn rust_uv_fs_rename(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char,
+                         to: *c_char, cb: *u8) -> c_int;
     fn rust_uv_fs_readdir(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char,
                         flags: c_int, cb: *u8) -> c_int;
     fn rust_uv_fs_req_cleanup(req: *uv_fs_t);
diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs
index 82ff8071896..44d9f59c410 100644
--- a/src/libstd/rt/rtio.rs
+++ b/src/libstd/rt/rtio.rs
@@ -102,8 +102,9 @@ pub trait IoFactory {
         -> Result<~RtioFileStream, IoError>;
     fn fs_unlink(&mut self, path: &CString) -> Result<(), IoError>;
     fn fs_stat(&mut self, path: &CString) -> Result<FileStat, IoError>;
-    fn fs_mkdir(&mut self, path: &CString) -> Result<(), IoError>;
+    fn fs_mkdir(&mut self, path: &CString, mode: int) -> Result<(), IoError>;
     fn fs_rmdir(&mut self, path: &CString) -> Result<(), IoError>;
+    fn fs_rename(&mut self, path: &CString, to: &CString) -> Result<(), IoError>;
     fn fs_readdir(&mut self, path: &CString, flags: c_int) ->
         Result<~[Path], IoError>;
     fn spawn(&mut self, config: ProcessConfig)
diff --git a/src/rt/rust_uv.cpp b/src/rt/rust_uv.cpp
index c59dacab889..70602100f2e 100644
--- a/src/rt/rust_uv.cpp
+++ b/src/rt/rust_uv.cpp
@@ -592,6 +592,11 @@ extern "C" int
 rust_uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) {
   return uv_fs_readdir(loop, req, path, flags, cb);
 }
+extern "C" int
+rust_uv_fs_rename(uv_loop_t *loop, uv_fs_t* req, const char *path,
+                  const char *to, uv_fs_cb cb) {
+    return uv_fs_rename(loop, req, path, to, cb);
+}
 
 extern "C" int
 rust_uv_spawn(uv_loop_t *loop, uv_process_t *p, uv_process_options_t options) {