scripts: Add zulip_tools.overwrite_symlink function to replace ln -nsf.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2018-07-26 19:23:27 -04:00 committed by Tim Abbott
parent 1597511de0
commit 33a4d12101
1 changed files with 18 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import shlex
import shutil
import subprocess
import sys
import tempfile
import time
import json
import uuid
@ -38,6 +39,23 @@ BLUE = '\x1b[34m'
MAGENTA = '\x1b[35m'
CYAN = '\x1b[36m'
def overwrite_symlink(src, dst):
# type: (str, str) -> None
while True:
tmp = tempfile.mktemp(
prefix='.' + os.path.basename(dst) + '.',
dir=os.path.dirname(dst))
try:
os.symlink(src, tmp)
except FileExistsError:
continue
break
try:
os.rename(tmp, dst)
except Exception:
os.remove(tmp)
raise
def parse_cache_script_args(description):
# type: (str) -> argparse.Namespace
parser = argparse.ArgumentParser(description=description)