Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-37612: always call linkat() from os.link(), if available
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.
  • Loading branch information
jo-he committed Jul 18, 2019
commit ae2e6e84fea71817e8972da08d15d21b33287988
12 changes: 4 additions & 8 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3512,15 +3512,11 @@ os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
#else
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_LINKAT
if ((src_dir_fd != DEFAULT_DIR_FD) ||
(dst_dir_fd != DEFAULT_DIR_FD) ||
(!follow_symlinks))
result = linkat(src_dir_fd, src->narrow,
dst_dir_fd, dst->narrow,
follow_symlinks ? AT_SYMLINK_FOLLOW : 0);
else
result = linkat(src_dir_fd, src->narrow, dst_dir_fd, dst->narrow,
follow_symlinks ? AT_SYMLINK_FOLLOW : 0);
#else
result = link(src->narrow, dst->narrow);
#endif /* HAVE_LINKAT */
result = link(src->narrow, dst->narrow);
Py_END_ALLOW_THREADS

if (result)
Expand Down