diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 8b3cbc2f0..eb0e4d25d 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -668,6 +668,19 @@ class PosixTester(unittest.TestCase): finally: fp.close() + @unittest.expectedFailure # TODO: RUSTPYTHON + @unittest.skipUnless(hasattr(posix, 'stat'), + 'test needs posix.stat()') + @unittest.skipUnless(os.stat in os.supports_follow_symlinks, + 'test needs follow_symlinks support in os.stat()') + def test_stat_fd_zero_follow_symlinks(self): + with self.assertRaisesRegex(ValueError, + 'cannot use fd and follow_symlinks together'): + posix.stat(0, follow_symlinks=False) + with self.assertRaisesRegex(ValueError, + 'cannot use fd and follow_symlinks together'): + posix.stat(1, follow_symlinks=False) + def test_stat(self): self.assertTrue(posix.stat(os_helper.TESTFN)) self.assertTrue(posix.stat(os.fsencode(os_helper.TESTFN))) @@ -1017,7 +1030,6 @@ class PosixTester(unittest.TestCase): target = self.tempdir() self.check_chmod(posix.chmod, target) - @unittest.skipIf(sys.platform in ("darwin", "linux"), "TODO: RUSTPYTHON; crash") @os_helper.skip_unless_working_chmod def test_fchmod_file(self): with open(os_helper.TESTFN, 'wb+') as f: diff --git a/crates/vm/src/stdlib/posix.rs b/crates/vm/src/stdlib/posix.rs index f873613d7..87c4fa5c8 100644 --- a/crates/vm/src/stdlib/posix.rs +++ b/crates/vm/src/stdlib/posix.rs @@ -1035,7 +1035,7 @@ pub mod module { fn _fchmod(fd: BorrowedFd<'_>, mode: u32, vm: &VirtualMachine) -> PyResult<()> { nix::sys::stat::fchmod( fd, - nix::sys::stat::Mode::from_bits(mode as libc::mode_t).unwrap(), + nix::sys::stat::Mode::from_bits_truncate(mode as libc::mode_t), ) .map_err(|err| err.into_pyexception(vm)) } @@ -1404,12 +1404,7 @@ pub mod module { } // cfg from nix - #[cfg(any( - target_os = "android", - target_os = "freebsd", - target_os = "linux", - target_os = "openbsd" - ))] + #[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "openbsd"))] #[pyfunction] fn setresgid(rgid: Gid, egid: Gid, sgid: Gid, vm: &VirtualMachine) -> PyResult<()> { unistd::setresgid(rgid, egid, sgid).map_err(|err| err.into_pyexception(vm)) @@ -1423,12 +1418,7 @@ pub mod module { } // cfg from nix - #[cfg(any( - target_os = "android", - target_os = "freebsd", - target_os = "linux", - target_os = "openbsd" - ))] + #[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "openbsd"))] #[pyfunction] fn initgroups(user_name: PyUtf8StrRef, gid: Gid, vm: &VirtualMachine) -> PyResult<()> { let user = user_name.to_cstring(vm)?;