diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-10-25 16:50:08 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-11-03 15:15:41 -0800 |
| commit | 7bf58c2baaac3f7cb3c8e8d735b27ac9e7d3cd78 (patch) | |
| tree | 398fa2a360e660fa4e6fc05a5994a2dce67318dc /src | |
| parent | d7b6502784cad759cee9961426313017f052d5ba (diff) | |
| download | rust-7bf58c2baaac3f7cb3c8e8d735b27ac9e7d3cd78.tar.gz rust-7bf58c2baaac3f7cb3c8e8d735b27ac9e7d3cd78.zip | |
Modify IoFactory's fs_mkdir, and add fs_rename
The invocation for making a directory should be able to specify a mode to make the directory with (instead of defaulting to one particular mode). Additionally, libuv and various OSes implement efficient versions of renaming files, so this operation is exposed as an IoFactory call.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustuv/file.rs | 15 | ||||
| -rw-r--r-- | src/librustuv/uvio.rs | 14 | ||||
| -rw-r--r-- | src/librustuv/uvll.rs | 8 | ||||
| -rw-r--r-- | src/libstd/rt/rtio.rs | 3 | ||||
| -rw-r--r-- | src/rt/rust_uv.cpp | 5 |
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) { |
