This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jo-he
Recipients eryksun, jo-he, larry, serhiy.storchaka
Date 2019-07-18.11:23:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1563448987.66.0.398587734496.issue37612@roundup.psfhosted.org>
In-reply-to
Content
The problem that POSIX does not define the behavior of link() regarding symlinks (and that Unix implementations differ indeed), is independent from Python's os.link() defaults.

Since it makes no sense to call link(), when linkat() is available, I propose this change:

--- 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)


This fix also simplifies the code, and should be safe for back-porting.

Whether Python's defaults should be changed regarding Windows and those (mostly obsolete) Unix platforms that do not provide linkat(), is another question.
History
Date User Action Args
2019-07-18 11:23:07jo-hesetrecipients: + jo-he, larry, serhiy.storchaka, eryksun
2019-07-18 11:23:07jo-hesetmessageid: <1563448987.66.0.398587734496.issue37612@roundup.psfhosted.org>
2019-07-18 11:23:07jo-helinkissue37612 messages
2019-07-18 11:23:07jo-hecreate