8000 Fix macos shutil · RustPython/RustPython@e7bfbcc · GitHub
[go: up one dir, main page]

Skip to content

Commit e7bfbcc

Browse files
committed
Fix macos shutil
1 parent 49cfcd8 commit e7bfbcc

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Lib/test/test_shutil.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,6 @@ def test_copymode_follow_symlinks(self):
10881088
shutil.copymode(src_link, dst_link)
10891089
self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
10901090

1091-
# TODO: RUSTPYTHON
1092-
@unittest.expectedFailure
10931091
@unittest.skipUnless(hasattr(os, 'lchmod') or os.name == 'nt', 'requires os.lchmod')
10941092
@os_helper.skip_unless_symlink
10951093
def test_copymode_symlink_to_symlink(self):
@@ -3008,7 +3006,6 @@ def test_unhandled_exception(self):
30083006
self.assertRaises(ZeroDivisionError,
30093007
shutil.copyfile, TESTFN, TESTFN2)
30103008

3011-
@unittest.skipIf(sys.platform == "darwin", "TODO: RUSTPYTHON, OSError.error on macOS")
30123009
def test_exception_on_first_call(self):
30133010
# Emulate a case where the first call to the zero-copy
30143011
# function raises an exception in which case the function is
@@ -3019,7 +3016,6 @@ def test_exception_on_first_call(self):
30193016
with self.assertRaises(_GiveupOnFastCopy):
30203017
self.zerocopy_fun(src, dst)
30213018

3022-
@unittest.skipIf(sys.platform == "darwin", "TODO: RUSTPYTHON, OSError.error on macOS")
30233019
def test_filesystem_full(self):
30243020
# Emulate a case where filesystem is full and sendfile() fails
30253021
# on first call.

vm/src/stdlib/posix.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,16 @@ pub mod module {
966966
#[cfg(not(target_os = "redox"))]
967967
#[pyfunction]
968968
fn lchmod(path: OsPath, mode: u32, vm: &VirtualMachine) -> PyResult<()> {
969-
_chmod(path, DirFd::default(), mode, FollowSymlinks(false), vm)
969+
extern "C" {
970+
fn lchmod(path: *const libc::c_char, mode: libc::mode_t) -> libc::c_int;
971+
}
972+
let c_path = path.clone().into_cstring(vm)?;
973+
if unsafe { lchmod(c_path.as_ptr(), mode as libc::mode_t) } == 0 {
974+
Ok(())
975+
} else {
976+
let err = std::io::Error::last_os_error();
977+
Err(IOErrorBuilder::with_filename(&err, path, vm))
978+
}
970979
}
971980

972981
#[pyfunction]

0 commit comments

Comments
 (0)
0