]> git.lizzy.rs Git - rust.git/commitdiff
Modify IoFactory's fs_mkdir, and add fs_rename
authorAlex Crichton <alex@alexcrichton.com>
Fri, 25 Oct 2013 23:50:08 +0000 (16:50 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 3 Nov 2013 23:15:41 +0000 (15:15 -0800)
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.

src/librustuv/file.rs
src/librustuv/uvio.rs
src/librustuv/uvll.rs
src/libstd/rt/rtio.rs
src/rt/rust_uv.cpp

index 575226f79028b8d5f72741c03f5a741f4d8c6c60..2303721986c42edc0ee4a9df318b0cde8fccb226 100644 (file)
@@ -206,6 +206,21 @@ pub fn rmdir(self, loop_: &Loop, path: &CString, cb: FsCallback) {
         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 = {
index c34d20ed4f50f93a0b542462f5c39463b5911355..7ecb51bb0d6ef0f04aa80ac709dd338ceebffd96 100644 (file)
@@ -699,10 +699,9 @@ fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>,
         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 @@ fn fs_rmdir(&mut self, path: &CString) -> Result<(), IoError> {
             };
         }
     }
+    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;
index 9e86ab11286e4d049f9690b97609aadbcb3dfe6c..9f26f9506a08401e6a98b4465f43cfc948187f00 100644 (file)
@@ -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 @@ fn rust_uv_fs_mkdir(loop_ptr: *c_void, req: *uv_fs_t, path: *c_char,
                         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);
index 82ff8071896fe07197fb7a46bebc26661882731e..44d9f59c4106206fba166231e830bc4b4fe960d9 100644 (file)
@@ -102,8 +102,9 @@ fn fs_open(&mut self, path: &CString, fm: FileMode, fa: FileAccess)
         -> 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)
index c59dacab88990863a046da9caa94b0bdf1d8aef9..70602100f2e0d4d584c3a3d24c92406a80ea6760 100644 (file)
@@ -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) {