Skip to content

bpo-37612: always call linkat() from os.link(), if available #14843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

jo-he
Copy link
Contributor

@jo-he jo-he commented Jul 18, 2019

The issue with link() is, that POSIX does not define its behavior regarding symbolic links:

"If path1 names a symbolic link, it is implementation-defined whether link() follows the symbolic link, or creates a new link to the symbolic link itself."

And it is indeed implemented differently on e.g. Linux and NetBSD. So, it makes no sense to call link(), where linkat() is available.

https://bugs.python.org/issue37612

The issue with link() is that POSIX does not define its behavior
regarding symbolic links:

"If path1 names a symbolic link, it is implementation-defined whether
link() follows the symbolic link, or creates a new link to the symbolic
link itself."

And it is indeed implemented differently on Linux and NetBSD.
@gnprice
Copy link
Contributor

gnprice commented Aug 1, 2019

As I understand it from your bpo report, the issue is that the behavior of os.link doesn't match its documentation on some platforms (in particular Linux), and this fixes things so that it does.

In particular the actual behavior on such platforms makes follow_symlinks=True useless, even when explicitly specified, so that's definitely a bug. (Also you located the relevant provision in POSIX and found that Linux's behavior here is perfectly compliant.)

That sounds like a good fix to me!

Would you add a test for it? See test_os.py, or perhaps test_posix.py if the test doesn't make sense to run on Windows.

@takluyver
Copy link
Contributor

I've had a go at adding the test in #24997.

@python-cla-bot
Copy link

The following commit authors need to sign the Contributor License Agreement:

CLA signed

@serhiy-storchaka
Copy link
Member

Fixed by #132517.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants