Skip to content

Commit e924993

Browse files
authored
Make Apple SDK path scripts not fail if symlinks already exist (#879)
1 parent 3c37b0f commit e924993

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

build/pyutil/file_util.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import errno
66
import os
7+
import uuid
78

89
"""Creates a directory and its parents (i.e. `mkdir -p`).
910
@@ -21,10 +22,16 @@ def mkdir_p(path):
2122
"""Creates or ovewrites a symlink from `link` to `target`."""
2223
def symlink(target, link):
2324
mkdir_p(os.path.dirname(link))
24-
tmp_link = link + '.tmp'
25+
tmp_link = link + '.tmp.' + uuid.uuid4().hex
2526
try:
2627
os.remove(tmp_link)
2728
except OSError:
2829
pass
2930
os.symlink(target, tmp_link)
30-
os.rename(tmp_link, link)
31+
try:
32+
os.rename(tmp_link, link)
33+
except FileExistsError:
34+
try:
35+
os.remove(tmp_link)
36+
except OSError:
37+
pass

0 commit comments

Comments
 (0)