Package: sagemath / 8.6-6

u1-fix-atrocious-symlink-logic.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Description: 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.
 We don't actually need any part of this file in Debian, but fixing this (so
 that post-install tests don't fail) was easier than trying to figure out if
 removing the file would have other consequences elsewhere.
Author: Ximin Luo <infinity0@debian.org>
Forwarded: https://trac.sagemath.org/ticket/22444
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/sage/src/sage/repl/ipython_kernel/install.py
+++ b/sage/src/sage/repl/ipython_kernel/install.py
@@ -107,12 +107,20 @@
             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
-        os.symlink(src, dst)
+            elif err.errno == errno.ENOENT:
+                pass
+            else:
+                raise
+        os.symlink(os.path.relpath(src, os.path.dirname(dst)), dst)
 
     def use_local_mathjax(self):
         """