diff options
author | Mani Maghsoudlou <manidlou@gmail.com> | 2018-09-12 08:44:58 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-09-12 11:44:58 -0400 |
commit | 88d42f0b189a1daa3fb44eb24ecad77823557d9f (patch) | |
tree | ac4d166271d9708472b16150f5f6dcc712095fcb /src | |
parent | 26081a32dfaf34fdc8b6cf53222c15f3d4e4f30d (diff) |
Implement deno.rename() (#731)
Diffstat (limited to 'src')
-rw-r--r-- | src/handlers.rs | 11 | ||||
-rw-r--r-- | src/msg.fbs | 4 |
2 files changed, 7 insertions, 8 deletions
diff --git a/src/handlers.rs b/src/handlers.rs index 681f18812..09b4e299a 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -55,7 +55,7 @@ pub extern "C" fn msg_from_js(d: *const DenoC, buf: deno_buf) { msg::Any::Mkdir => handle_mkdir, msg::Any::Remove => handle_remove, msg::Any::ReadFile => handle_read_file, - msg::Any::RenameSync => handle_rename_sync, + msg::Any::Rename => handle_rename, msg::Any::SetEnv => handle_set_env, msg::Any::Stat => handle_stat, msg::Any::WriteFile => handle_write_file, @@ -633,15 +633,14 @@ fn handle_timer_clear(d: *const DenoC, base: &msg::Base) -> Box<Op> { ok_future(None) } -fn handle_rename_sync(d: *const DenoC, base: &msg::Base) -> Box<Op> { +fn handle_rename(d: *const DenoC, base: &msg::Base) -> Box<Op> { let deno = from_c(d); if !deno.flags.allow_write { - return Box::new(futures::future::err(permission_denied())); - }; - let msg = base.msg_as_rename_sync().unwrap(); + return odd_future(permission_denied()); + } + let msg = base.msg_as_rename().unwrap(); let oldpath = String::from(msg.oldpath().unwrap()); let newpath = String::from(msg.newpath().unwrap()); - // TODO use blocking() Box::new(futures::future::result(|| -> OpResult { debug!("handle_rename {} {}", oldpath, newpath); fs::rename(Path::new(&oldpath), Path::new(&newpath))?; diff --git a/src/msg.fbs b/src/msg.fbs index 458f5f437..c630fec9d 100644 --- a/src/msg.fbs +++ b/src/msg.fbs @@ -19,7 +19,7 @@ union Any { ReadFile, ReadFileRes, WriteFile, - RenameSync, + Rename, Stat, StatRes, SetEnv, @@ -194,7 +194,7 @@ table WriteFile { // perm specified by https://godoc.org/os#FileMode } -table RenameSync { +table Rename { oldpath: string; newpath: string; } |