Skip to content

Commit 460350f

Browse files
authored
Revert to absolute symlinks if relative link generation fails (#30)
* Try absolute path for link if relative path fails * Raise error if link fails * Fix tests by adding missing link target
1 parent 412dfa1 commit 460350f

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

ecbundle/util.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def symlink_force(target, link_name):
105105

106106
# prefer relative symlink rather than absolute
107107
# check first if target is absolute or relative
108+
target_orig = target
108109
if os.path.isabs(target):
109110
target = os.path.relpath(target, os.path.dirname(link_name))
110111

@@ -117,6 +118,20 @@ def symlink_force(target, link_name):
117118
else:
118119
raise exc
119120

121+
# If a relative link is invalid, retry with absolute path if available
122+
if not os.path.exists(link_name):
123+
if target != target_orig:
124+
os.remove(link_name)
125+
os.symlink(target_orig, link_name)
126+
127+
if not os.path.exists(link_name):
128+
error(
129+
"ERROR: Failed to create valid link from {0} to {1}".format(
130+
link_name, target_orig
131+
)
132+
)
133+
raise RuntimeError()
134+
120135

121136
def copydir(src_dir, target_dir):
122137
import os
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

0 commit comments

Comments
 (0)