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.
This commit is contained in:
parent
d7b6502784
commit
7bf58c2baa
|
@ -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 = {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue