Skip to content

Commit

Permalink
Make Apple SDK path scripts not fail if symlinks already exist (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanderso committed Jul 25, 2024
1 parent 3c37b0f commit e924993
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions build/pyutil/file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import errno
import os
import uuid

"""Creates a directory and its parents (i.e. `mkdir -p`).
Expand All @@ -21,10 +22,16 @@ def mkdir_p(path):
"""Creates or ovewrites a symlink from `link` to `target`."""
def symlink(target, link):
mkdir_p(os.path.dirname(link))
tmp_link = link + '.tmp'
tmp_link = link + '.tmp.' + uuid.uuid4().hex
try:
os.remove(tmp_link)
except OSError:
pass
os.symlink(target, tmp_link)
os.rename(tmp_link, link)
try:
os.rename(tmp_link, link)
except FileExistsError:
try:
os.remove(tmp_link)
except OSError:
pass

0 comments on commit e924993

Please sign in to comment.