summaryrefslogtreecommitdiff
path: root/cli/fs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/fs.rs')
-rw-r--r--cli/fs.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/cli/fs.rs b/cli/fs.rs
index ff0da95e5..73d7701e6 100644
--- a/cli/fs.rs
+++ b/cli/fs.rs
@@ -8,11 +8,15 @@ use std::path::{Path, PathBuf};
use rand;
use rand::Rng;
+#[cfg(unix)]
+use nix::unistd::{chown as unix_chown, Gid, Uid};
#[cfg(any(unix))]
use std::os::unix::fs::DirBuilderExt;
#[cfg(any(unix))]
use std::os::unix::fs::PermissionsExt;
+use crate::errors::DenoResult;
+
pub fn write_file<T: AsRef<[u8]>>(
filename: &Path,
data: T,
@@ -108,3 +112,20 @@ pub fn normalize_path(path: &Path) -> String {
s
}
}
+
+#[cfg(unix)]
+pub fn chown(path: &str, uid: u32, gid: u32) -> DenoResult<()> {
+ use crate::errors::DenoError;
+ let nix_uid = Uid::from_raw(uid);
+ let nix_gid = Gid::from_raw(gid);
+ unix_chown(path, Option::Some(nix_uid), Option::Some(nix_gid))
+ .map_err(DenoError::from)
+}
+
+#[cfg(not(unix))]
+pub fn chown(_path: &str, _uid: u32, _gid: u32) -> DenoResult<()> {
+ // Noop
+ // TODO: implement chown for Windows
+ use crate::errors;
+ Err(errors::op_not_implemented())
+}