Commit 9792c816 authored by Ben Gamari's avatar Ben Gamari 🐢 Committed by Marge Bot

testsuite: Probe whether symlinks are usable on Windows

Closes #17706.
parent 9e851472
import os
import subprocess
import shutil
import tempfile
from pathlib import Path, PurePath
from term_color import Color, colored
......@@ -82,7 +83,28 @@ def testing_metrics():
# We define the following function to make this magic more
# explicit/discoverable. You are encouraged to use it instead of os.symlink.
if == 'nt' and os.getenv('FORCE_SYMLINKS') == None:
def symlinks_work() -> bool:
if os.getenv('FORCE_SYMLINKS') is not None:
return True
elif == 'nt':
# On Windows we try to create a symlink to test whether symlinks are
# usable.
works = False
with tempfile.NamedTemporaryFile() as tmp:
os.symlink(, '__symlink-test')
works = True
except OSError as e:
print('Saw {} during symlink test; assuming symlinks do not work.'.format(e))
return works
return True
if not symlinks_work():
def link_or_copy_file(src: Path, dst: Path):
shutil.copyfile(str(src), str(dst))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment