From ae2e6e84fea71817e8972da08d15d21b33287988 Mon Sep 17 00:00:00 2001 From: Joachim Henke <37883863+jo-he@users.noreply.github.com> Date: Thu, 18 Jul 2019 08:50:23 +0200 Subject: [PATCH 1/2] 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. --- Modules/posixmodule.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 777e933cab59b5..9e9a119b1418cc 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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) From 264bdad2e41669ee5955eb5cab43adc95ad55889 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 19 Jul 2019 09:57:19 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2019-07-19-09-57-18.bpo-37612.yjjxx-.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2019-07-19-09-57-18.bpo-37612.yjjxx-.rst diff --git a/Misc/NEWS.d/next/Library/2019-07-19-09-57-18.bpo-37612.yjjxx-.rst b/Misc/NEWS.d/next/Library/2019-07-19-09-57-18.bpo-37612.yjjxx-.rst new file mode 100644 index 00000000000000..85d2775110ac9e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-07-19-09-57-18.bpo-37612.yjjxx-.rst @@ -0,0 +1 @@ +fix os.link() on platforms (like Linux) where the system link() function does not follow symlinks \ No newline at end of file