mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00:00
feat: Deno.chown() make uid, gid args optional (#4612)
This commit is contained in:
parent
79610378d3
commit
6b78729ba8
4 changed files with 175 additions and 181 deletions
|
@ -475,8 +475,8 @@ fn op_chmod(
|
|||
struct ChownArgs {
|
||||
promise_id: Option<u64>,
|
||||
path: String,
|
||||
uid: u32,
|
||||
gid: u32,
|
||||
uid: Option<u32>,
|
||||
gid: Option<u32>,
|
||||
}
|
||||
|
||||
fn op_chown(
|
||||
|
@ -491,20 +491,18 @@ fn op_chown(
|
|||
|
||||
let is_sync = args.promise_id.is_none();
|
||||
blocking_json(is_sync, move || {
|
||||
debug!("op_chown {} {} {}", path.display(), args.uid, args.gid);
|
||||
debug!("op_chown {} {:?} {:?}", path.display(), args.uid, args.gid,);
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use nix::unistd::{chown, Gid, Uid};
|
||||
let nix_uid = Uid::from_raw(args.uid);
|
||||
let nix_gid = Gid::from_raw(args.gid);
|
||||
chown(&path, Option::Some(nix_uid), Option::Some(nix_gid))?;
|
||||
let nix_uid = args.uid.map(Uid::from_raw);
|
||||
let nix_gid = args.gid.map(Gid::from_raw);
|
||||
chown(&path, nix_uid, nix_gid)?;
|
||||
Ok(json!({}))
|
||||
}
|
||||
// TODO Implement chown for Windows
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
// Still check file/dir exists on Windows
|
||||
let _metadata = std::fs::metadata(&path)?;
|
||||
Err(OpError::not_implemented())
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue