8000 chmod+follow_symlinks=False calls lchmod · RustPython/RustPython@d7bd966 · GitHub
[go: up one dir, main page]

Skip to content

Commit d7bd966

Browse files
committed
chmod+follow_symlinks=False calls lchmod
1 parent e7bfbcc commit d7bd966

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

vm/src/stdlib/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ cfg_if::cfg_if! {
4848
const DEFAULT_DIR_FD: Fd = Fd(AT_FDCWD);
4949

5050
// XXX: AVAILABLE should be a bool, but we can't yet have it as a bool and just cast it to usize
51-
#[derive(Copy, Clone)]
51+
#[derive(Copy, Clone, PartialEq, Eq)]
5252
pub struct DirFd<const AVAILABLE: usize>(pub(crate) [Fd; AVAILABLE]);
5353

5454
impl<const AVAILABLE: usize> Default for DirFd<AVAILABLE> {

vm/src/stdlib/posix.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,13 @@ pub mod module {
940940
vm: &VirtualMachine,
941941
) -> PyResult<()> {
942942
match path {
943-
OsPathOrFd::Path(path) => _chmod(path, dir_fd, mode, follow_symlinks, vm),
943+
OsPathOrFd::Path(path) => {
944+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "netbsd",))]
945+
if !follow_symlinks.0 && dir_fd == Default::default() {
946+
return lchmod(path, mode, vm);
947+
}
948+
_chmod(path, dir_fd, mode, follow_symlinks, vm)
949+
}
944950
OsPathOrFd::Fd(fd) => _fchmod(fd, mode, vm),
945951
}
946952
}
@@ -963,7 +969,7 @@ pub mod module {
963969
_fchmod(fd, mode, vm)
964970
}
965971

966-
#[cfg(not(target_os = "redox"))]
972+
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "netbsd",))]
967973
#[pyfunction]
968974
fn lchmod(path: OsPath, mode: u32, vm: &VirtualMachine) -> PyResult<()> {
969975
extern "C" {
@@ -1700,7 +1706,22 @@ pub mod module {
17001706

17011707
pub(crate) fn support_funcs() -> Vec<SupportFunc> {
17021708
vec![
1703-
SupportFunc::new("chmod", Some(false), Some(false), Some(false)),
1709+
SupportFunc::new(
1710+
"chmod",
1711+
Some(false),
1712+
Some(false),
1713+
Some(
1714+
if cfg!(any(
1715< 815B /td>+
target_os = "macos",
1716+
target_os = "freebsd",
1717+
target_os = "netbsd"
1718+
)) {
1719+
true
1720+
} else {
1721+
false
1722+
},
1723+
),
1724+
),
17041725
#[cfg(not(target_os = "redox"))]
17051726
SupportFunc::new("chroot", Some(false), None, None),
17061727
#[cfg(not(target_os = "redox"))]

0 commit comments

Comments
 (0)
0