From 5bea62ac321c33ee8a65d02e14d101f035589fb3 Mon Sep 17 00:00:00 2001 From: JaePil Jung <jjp5023@gmail.com> Date: Thu, 13 Sep 2018 04:17:17 +0900 Subject: [PATCH] Small handers.rs cleanup (#735) --- src/handlers.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/handlers.rs b/src/handlers.rs index 326c2f2dd4..641bfd83c1 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -420,7 +420,7 @@ fn handle_make_temp_dir(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())); + return odd_future(permission_denied()); } // TODO Use blocking() here. Box::new(futures::future::result(|| -> OpResult { @@ -590,16 +590,15 @@ fn handle_write_file(d: *const DenoC, base: &msg::Base) -> Box<Op> { let filename = String::from(msg.filename().unwrap()); let data = msg.data().unwrap(); let perm = msg.perm(); - let deno = from_c(d); - debug!("handle_write_file {}", filename); + let deno = from_c(d); + if !deno.flags.allow_write { + return odd_future(permission_denied()); + } Box::new(futures::future::result(|| -> OpResult { - if !deno.flags.allow_write { - Err(permission_denied()) - } else { - deno_fs::write_file(Path::new(&filename), data, perm)?; - Ok(None) - } + debug!("handle_write_file {}", filename); + deno_fs::write_file(Path::new(&filename), data, perm)?; + Ok(None) }())) } @@ -664,7 +663,7 @@ fn handle_rename(d: *const DenoC, base: &msg::Base) -> Box<Op> { let deno = from_c(d); if !deno.flags.allow_write { 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());