MCPcopy Index your code
hub / github.com/RustPython/RustPython / chown

Function chown

crates/vm/src/stdlib/posix.rs:615–656  ·  view source on GitHub ↗
(
        path: OsPathOrFd<'_>,
        uid: isize,
        gid: isize,
        dir_fd: DirFd<'_, 1>,
        follow_symlinks: FollowSymlinks,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

613 #[cfg(not(target_os = "redox"))]
614 #[pyfunction]
615 fn chown(
616 path: OsPathOrFd<'_>,
617 uid: isize,
618 gid: isize,
619 dir_fd: DirFd<'_, 1>,
620 follow_symlinks: FollowSymlinks,
621 vm: &VirtualMachine,
622 ) -> PyResult<()> {
623 let uid = if uid >= 0 {
624 Some(nix::unistd::Uid::from_raw(uid as u32))
625 } else if uid == -1 {
626 None
627 } else {
628 return Err(vm.new_os_error("Specified uid is not valid."));
629 };
630
631 let gid = if gid >= 0 {
632 Some(nix::unistd::Gid::from_raw(gid as u32))
633 } else if gid == -1 {
634 None
635 } else {
636 return Err(vm.new_os_error("Specified gid is not valid."));
637 };
638
639 let flag = if follow_symlinks.0 {
640 nix::fcntl::AtFlags::empty()
641 } else {
642 nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW
643 };
644
645 match path {
646 OsPathOrFd::Path(ref p) => {
647 nix::unistd::fchownat(dir_fd.get(), p.path.as_os_str(), uid, gid, flag)
648 }
649 OsPathOrFd::Fd(fd) => nix::unistd::fchown(fd, uid, gid),
650 }
651 .map_err(|err| {
652 // Use `From<nix::Error> for io::Error` when it is available
653 let err = io::Error::from_raw_os_error(err as i32);
654 OSErrorBuilder::with_filename(&err, path, vm)
655 })
656 }
657
658 #[cfg(not(target_os = "redox"))]
659 #[pyfunction]

Callers 2

lchownFunction · 0.70
fchownFunction · 0.70

Calls 6

fchownFunction · 0.85
new_os_errorMethod · 0.80
as_os_strMethod · 0.80
SomeClass · 0.50
ErrClass · 0.50
getMethod · 0.45

Tested by

no test coverage detected