summaryrefslogtreecommitdiff
path: root/cli/ops.rs
diff options
context:
space:
mode:
authorYingbo (Max) Wang <maxwyb@gmail.com>2019-05-07 18:58:58 -0700
committerRyan Dahl <ry@tinyclouds.org>2019-05-07 21:58:57 -0400
commitec9080f34c936d9af56cca68de664954053bf423 (patch)
treeede97b27acebc225cc69da70433b626af63cc0e6 /cli/ops.rs
parent1f7ad17152c03b140c997590c897b89fbfea7cea (diff)
Add Deno.chown (#2292)
Diffstat (limited to 'cli/ops.rs')
-rw-r--r--cli/ops.rs25
1 files changed, 25 insertions, 0 deletions
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<OpCreator> {
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<PinnedBuf>,
+) -> Box<OpWithError> {
+ 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<'_>,