mirror of https://github.com/zulip/zulip.git
scripts: Add zulip_tools.overwrite_symlink function to replace ln -nsf.
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
parent
1597511de0
commit
33a4d12101
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue