From ec9080f34c936d9af56cca68de664954053bf423 Mon Sep 17 00:00:00 2001 From: "Yingbo (Max) Wang" Date: Tue, 7 May 2019 18:58:58 -0700 Subject: Add Deno.chown (#2292) --- cli/ops.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'cli/ops.rs') diff --git a/cli/ops.rs b/cli/ops.rs index ab2284110..7b9500ef8 100644 --- a/cli/ops.rs +++ b/cli/ops.rs @@ -186,6 +186,7 @@ pub fn op_selector_std(inner_type: msg::Any) -> Option { msg::Any::Accept => Some(op_accept), msg::Any::Chdir => Some(op_chdir), msg::Any::Chmod => Some(op_chmod), + msg::Any::Chown => Some(op_chown), msg::Any::Close => Some(op_close), msg::Any::CopyFile => Some(op_copy_file), msg::Any::Cwd => Some(op_cwd), @@ -869,6 +870,30 @@ fn op_chmod( }) } +fn op_chown( + state: &ThreadSafeState, + base: &msg::Base<'_>, + data: Option, +) -> Box { + assert!(data.is_none()); + let inner = base.inner_as_chown().unwrap(); + let path = String::from(inner.path().unwrap()); + let uid = inner.uid(); + let gid = inner.gid(); + + if let Err(e) = state.check_write(&path) { + return odd_future(e); + } + + blocking(base.sync(), move || { + debug!("op_chown {}", &path); + match deno_fs::chown(&path, uid, gid) { + Ok(_) => Ok(empty_buf()), + Err(e) => Err(e), + } + }) +} + fn op_open( state: &ThreadSafeState, base: &msg::Base<'_>, -- cgit v1.2.3