[issue37612] os.link(..., follow_symlinks=True) broken on Linux
Jo Henke
report at bugs.python.org
Thu Jul 18 07:23:07 EDT 2019
Jo Henke <free.software at gmx.com> added the comment:
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.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37612>
_______________________________________
More information about the Python-bugs-list
mailing list