Bug report
Bug description:
The documentation for os.chmod says it is not correct to use dir_fd or follow_symlinks when path is an open file descriptor...
|
It is an error to use dir_fd or follow_symlinks when specifying path as |
|
an open file descriptor. |
|
dir_fd and follow_symlinks may not be implemented on your platform. |
|
If they are unavailable, using them will raise a NotImplementedError. |
... but os_chmod_impl never checks it.
When path->is_fd is true it takes the fchmod path and returns success, so both keywords are ignored altogether:
|
#ifdef HAVE_FCHMOD |
|
if (path->is_fd) { |
|
result = fchmod(path->fd, mode); |
|
} |
Other os utils (I checked os.stat, os.chown, and os.utime) reject this combination with dir_fd_and_fd_invalid / fd_and_follow_symlinks_invalid before the syscall. os.chown for example:
|
if (dir_fd_and_fd_invalid("chown", dir_fd, path->fd) || |
|
fd_and_follow_symlinks_invalid("chown", path->is_fd, follow_symlinks)) |
|
return NULL; |
(The Windows path also has the same problem with: path->is_fd going directly to win32_fchmod.)
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
Bug report
Bug description:
The documentation for
os.chmodsays it is not correct to usedir_fdorfollow_symlinkswhenpathis an open file descriptor...cpython/Modules/posixmodule.c
Lines 4092 to 4095 in f74cdf8
... but
os_chmod_implnever checks it.When
path->is_fdis true it takes thefchmodpath and returns success, so both keywords are ignored altogether:cpython/Modules/posixmodule.c
Lines 4146 to 4149 in f74cdf8
Other
osutils (I checkedos.stat,os.chown, andos.utime) reject this combination withdir_fd_and_fd_invalid/fd_and_follow_symlinks_invalidbefore the syscall.os.chownfor example:cpython/Modules/posixmodule.c
Lines 4548 to 4550 in f74cdf8
(The Windows path also has the same problem with:
path->is_fdgoing directly towin32_fchmod.)CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
os.chmod#156265