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

Method stat

crates/vm/src/stdlib/os.rs:761–810  ·  view source on GitHub ↗
(
            &self,
            dir_fd: DirFd<'_, { STAT_DIR_FD as usize }>,
            follow_symlinks: FollowSymlinks,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

759
760 #[pymethod]
761 fn stat(
762 &self,
763 dir_fd: DirFd<'_, { STAT_DIR_FD as usize }>,
764 follow_symlinks: FollowSymlinks,
765 vm: &VirtualMachine,
766 ) -> PyResult {
767 // Use stored dir_fd if the caller didn't provide one
768 let effective_dir_fd = if dir_fd == DirFd::default() {
769 self.stat_dir_fd()
770 } else {
771 dir_fd
772 };
773 let do_stat = |follow_symlinks| {
774 stat(
775 OsPath {
776 path: self.pathval.as_os_str().to_owned(),
777 origin: None,
778 }
779 .into(),
780 effective_dir_fd,
781 FollowSymlinks(follow_symlinks),
782 vm,
783 )
784 };
785 let lstat = || match self.lstat.get() {
786 Some(val) => Ok(val),
787 None => {
788 let val = do_stat(false)?;
789 let _ = self.lstat.set(val);
790 Ok(self.lstat.get().unwrap())
791 }
792 };
793 let stat = if follow_symlinks.0 {
794 match self.stat.get() {
795 Some(val) => val,
796 None => {
797 let val = if self.is_symlink(vm)? {
798 do_stat(true)?
799 } else {
800 lstat()?.clone()
801 };
802 let _ = self.stat.set(val);
803 self.stat.get().unwrap()
804 }
805 }
806 } else {
807 lstat()?
808 };
809 Ok(stat.clone())
810 }
811
812 #[cfg(windows)]
813 #[pymethod]

Callers 2

_path_statFunction · 0.45
test_mode_via_statMethod · 0.45

Calls 11

statFunction · 0.85
FollowSymlinksClass · 0.85
lstatFunction · 0.85
stat_dir_fdMethod · 0.80
as_os_strMethod · 0.80
to_ownedMethod · 0.45
getMethod · 0.45
setMethod · 0.45
unwrapMethod · 0.45
is_symlinkMethod · 0.45
cloneMethod · 0.45

Tested by 1

test_mode_via_statMethod · 0.36