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

Function win32_lchmod

crates/vm/src/stdlib/nt.rs:327–347  ·  view source on GitHub ↗
(path: &OsPath, mode: u32, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

325 }
326
327 fn win32_lchmod(path: &OsPath, mode: u32, vm: &VirtualMachine) -> PyResult<()> {
328 use windows_sys::Win32::Storage::FileSystem::{GetFileAttributesW, SetFileAttributesW};
329
330 let wide = path.to_wide_cstring(vm)?;
331 let attr = unsafe { GetFileAttributesW(wide.as_ptr()) };
332 if attr == FileSystem::INVALID_FILE_ATTRIBUTES {
333 let err = io::Error::last_os_error();
334 return Err(OSErrorBuilder::with_filename(&err, path.clone(), vm));
335 }
336 let new_attr = if mode & S_IWRITE != 0 {
337 attr & !FileSystem::FILE_ATTRIBUTE_READONLY
338 } else {
339 attr | FileSystem::FILE_ATTRIBUTE_READONLY
340 };
341 let ret = unsafe { SetFileAttributesW(wide.as_ptr(), new_attr) };
342 if ret == 0 {
343 let err = io::Error::last_os_error();
344 return Err(OSErrorBuilder::with_filename(&err, path.clone(), vm));
345 }
346 Ok(())
347 }
348
349 #[pyfunction]
350 fn fchmod(fd: i32, mode: u32, vm: &VirtualMachine) -> PyResult<()> {

Callers 1

chmodFunction · 0.85

Calls 4

ErrClass · 0.50
to_wide_cstringMethod · 0.45
as_ptrMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected