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

Method test_mode_via_stat

crates/vm/src/stdlib/os.rs:664–684  ·  view source on GitHub ↗
(
            &self,
            follow_symlinks: bool,
            mode_bits: u32,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

662 /// Stat-based mode test fallback. Uses fstatat when dir_fd is available.
663 #[cfg(unix)]
664 fn test_mode_via_stat(
665 &self,
666 follow_symlinks: bool,
667 mode_bits: u32,
668 vm: &VirtualMachine,
669 ) -> PyResult<bool> {
670 match self.stat(self.stat_dir_fd(), FollowSymlinks(follow_symlinks), vm) {
671 Ok(stat_obj) => {
672 let st_mode: i32 = stat_obj.get_attr("st_mode", vm)?.try_into_value(vm)?;
673 #[allow(clippy::unnecessary_cast)]
674 Ok((st_mode as u32 & libc::S_IFMT as u32) == mode_bits)
675 }
676 Err(e) => {
677 if e.fast_isinstance(vm.ctx.exceptions.file_not_found_error) {
678 Ok(false)
679 } else {
680 Err(e)
681 }
682 }
683 }
684 }
685
686 #[pymethod]
687 fn is_dir(&self, follow_symlinks: FollowSymlinks, vm: &VirtualMachine) -> PyResult<bool> {

Callers 3

is_dirMethod · 0.80
is_fileMethod · 0.80
is_symlinkMethod · 0.80

Calls 7

FollowSymlinksClass · 0.85
stat_dir_fdMethod · 0.80
try_into_valueMethod · 0.80
fast_isinstanceMethod · 0.80
ErrClass · 0.50
statMethod · 0.45
get_attrMethod · 0.45

Tested by

no test coverage detected