I had written a script using os.fwalk() and os.lstat(), which was working.
Then I added an if os.lstat in os.supports_dir_fd check and a fallback implementation and observed the fallback path being taken:
It included _add("HAVE_FSTATAT","stat") but not included _add("HAVE_LSTAT","lstat"). I am uncertain whether this was intentionally designed or, in the alternative, we should incorporate it.
Activity
zangjiucheng commented on Jun 4, 2025
Hi there, I tested this code and reproduce the case as you described.
I noticed the following code in os.py; it includes all the attributes included in supports_dir_fd.
cpython/Lib/os.py
Line 120 in c211130
It included _add("HAVE_FSTATAT","stat") but not included _add("HAVE_LSTAT","lstat"). I am uncertain whether this was intentionally designed or, in the alternative, we should incorporate it.
Reference:
https://linux.die.net/man/2/lstat
pythongh-134993: Add os.lstat() to os.supports_dir_fd
vstinner commented on Jun 5, 2025
I proposed #135188 to fix the issue.
gh-134993: Add os.lstat() to os.supports_dir_fd (#135188)
pythongh-134993: Add os.lstat() to os.supports_dir_fd (pythonGH-135188)
pythongh-134993: Add os.lstat() to os.supports_dir_fd (pythonGH-135188)
vstinner commented on Jun 6, 2025
Fixed. Thanks for your report.
In the meanwhile, don't rely on os.supports_dir_fd but makes the assumption that os.lstat() supports dir_fd.
[3.13] gh-134993: Add os.lstat() to os.supports_dir_fd (GH-135188) (#…
[3.14] gh-134993: Add os.lstat() to os.supports_dir_fd (GH-135188) (#…
pythongh-134993: Add os.lstat() to os.supports_dir_fd (python#135188)
pythongh-134993: Add os.lstat() to os.supports_dir_fd (python#135188)
pythongh-134993: Add os.lstat() to os.supports_dir_fd (python#135188)
[3.12] gh-157579: Fix race condition in the cleanup of tempfile.Tempo…
pythongh-134993: Add os.lstat() to os.supports_dir_fd (python#135188)