Comments (5)
I investigated this problem about 4 years ago for issue gh-85527. It seems nothing was done to fix the implementation. It still defaults to follow_symlinks=True
, and the behavior still depends on the platform's implementation of link()
and whether src_dir_fd
or dst_dir_fd
is passed. For example, apparently link()
actually follows symlinks on macOS, which POSIX allows. (I don't use macOS, so I'm just repeating what was stated on the previous issue.)
By 'fixing' the code like this for Linux, you're breaking it for macOS, which would have no way to not follow symlinks. Instead, the implementation should always use linkat()
if it's available. Maybe the default in 3.14 should be follow_symlinks=None
, and use false as the real default on all platforms except for macOS. That would preserve existing default behavior in practice (documentation aside), except for the previously inconsistent behavior when src_dir_fd
or dst_dir_fd
was passed.
I'd prefer for the symlink-following behavior to be documented as platform-dependent if follow_symlinks
isn't supported. For Windows, there's a noteworthy inconsistency with POSIX. CreateHardLinkW()
is implemented to not follow symlinks, but, unlike POSIX, creating a hardlink to a directory symlink is disallowed because the symlink itself is a directory.
from cpython.
I think this issue is different to that one where that can be regarded as a API change request, this is a behavior correction without API change (keeps the default value True
) and I've add the corresponding tests.
from cpython.
The support for follow_symlinks
was implemented incorrectly when it was added in 3.3 (2012), so this has been broken for 12 years. It should never depend on calling the platform link()
when linkat()
is available, since POSIX allows the symlink behavior to be defined by the implementation. If HAVE_LINKAT_RUNTIME
is defined, then use linkat()
. Otherwise follow_symlinks
is not supported, so link()
is used, and the fact that the symlink behavior is platform-dependent should be documented.
The behavior of os.link(src, dst)
on Linux and BSD can certainly change in 3.14, but changing it for earlier versions seems dubious to me. The current overall behavior has been in place since follow_symlinks
support was added in 3.3, and the default behavior of os.link(src, dst)
has never changed since Python 1.x in the 1990s. It has always depended on the behavior of the platform link()
, which doesn't follow symlinks on Linux and BSD and does follow symlinks on macOS (2001+).
In Python 3.11-3.13, I'd prefer to change the default to follow_symlinks=False
, except if __APPLE__
is defined the default should be follow_symlinks=True
. Then change the documentation to make the default follow_symlinks=False
, but note the exception that it's True
on macOS. In 3.14, I'd prefer to make it consistently follow_symlinks=False
, which to me seems to be the more intuitive behavior for hardlinks, which is why it's the default behavior of POSIX linkat()
.
from cpython.
However changing the default value follows_symlinks=False
may leads a big compatibility break than what currently #119886 does, at least I think so.
from cpython.
The actual behavior has always been follow_symlinks=False
, except on macOS, or except if src_dir_fd
or dst_dir_fd
is passed as a real file descriptor.
from cpython.
Related Issues (20)
- Speed up open().read() pattern by reducing the number of system calls HOT 3
- make_ssl_certs fails with "no issuer certificate" with recent openssl HOT 1
- Hitting Assert for Managed Static Types During Subinterpreter Finalization HOT 3
- The New REPL Does Not Load My Command History HOT 1
- The New REPL Command History Does Not Honor Partial Text
- pdb repeats `w 0` on empty line when there are commands in `cmdqueue`
- Refactor `xml.etree.ElementTree._namespaces` HOT 1
- Introspective attributes of an async generator object are undocumented
- dis: LOAD_SPECIAL should mention the name of the attribute
- ``test_datetime`` fails with a ``--forever`` argument HOT 3
- UTC deprecation doc-string is false HOT 4
- logging.config: configuring root through dictConfig won't update already existing loggers HOT 1
- AttributeError: 'datetime.datetime' object has no attribute 'times' HOT 1
- [CI/CD] allow to skip tests that are know to lack a C (or Python) implementation. HOT 5
- a biit better example in pathlib docs - maybe include example path that involves file in a folder(s)? HOT 1
- Security branches: Consider fixing the documentation or adding a notice banner HOT 1
- New REPL omits local variables when running ./python -i script.py HOT 2
- importlib.metadata test fixtures should prefer test.support fixtures
- Lacking description of how to correctly implement indexing syntax support.
- Rewrite asyncio subprocesses without child watchers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpython.