From 316c6c37296e2548d4705b27a27fd845b640a42c Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Wed, 22 Feb 2017 01:34:21 +0100 Subject: [PATCH] Fix atrocious logic in symlink() If the desired result is already in effect, do nothing. Otherwise, proceed with the previous behaviour, but handle permissions errors correctly. --- src/sage/repl/ipython_kernel/install.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/sage/repl/ipython_kernel/install.py b/src/sage/repl/ipython_kernel/install.py index 45a3673b511..bba5d3c9935 100644 --- a/src/sage/repl/ipython_kernel/install.py +++ b/src/sage/repl/ipython_kernel/install.py @@ -89,11 +89,19 @@ def symlink(self, src, dst): sage: os.listdir(path) ['b'] """ + if os.path.islink(dst): + origsrc = os.path.join(os.path.dirname(dst), os.readlink(dst)) + if os.path.abspath(origsrc) == os.path.abspath(src): + return try: os.remove(dst) except OSError as err: if err.errno == errno.EEXIST: return + elif err.errno == errno.ENOENT: + pass + else: + raise os.symlink(src, dst) def use_local_mathjax(self):