summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-02-06 20:08:52 -0500
committerBen Gamari <ben@smart-cactus.org>2020-02-10 11:33:44 -0500
commit4b195a5379b59beb9a477d0f1a67934a337f130a (patch)
treec4fb71d7b5bfd32afc871eea1d7984f0e032e722
parente8004e5d1e993363a89b0107380604c5bc02be6b (diff)
downloadhaskell-wip/windows-symlink.tar.gz
testsuite: Probe whether symlinks are usable on Windowswip/windows-symlink
Closes #17706.
-rw-r--r--testsuite/driver/testutil.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/testsuite/driver/testutil.py b/testsuite/driver/testutil.py
index 62b76c75fd..4c2f3ffdee 100644
--- a/testsuite/driver/testutil.py
+++ b/testsuite/driver/testutil.py
@@ -1,6 +1,7 @@
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 os.name == 'nt' and os.getenv('FORCE_SYMLINKS') == None:
+def symlinks_work() -> bool:
+ if os.getenv('FORCE_SYMLINKS') is not None:
+ return True
+ elif os.name == 'nt':
+ # On Windows we try to create a symlink to test whether symlinks are
+ # usable.
+ works = False
+ with tempfile.NamedTemporaryFile() as tmp:
+ try:
+ tmp.write('hello')
+ os.symlink(tmp.name, '__symlink-test')
+ works = True
+ except OSError as e:
+ print('Saw {} during symlink test; assuming symlinks do not work.'.format(e))
+ finally:
+ os.unlink('__symlink-test')
+
+ return works
+ else:
+ return True
+
+if not symlinks_work():
def link_or_copy_file(src: Path, dst: Path):
shutil.copyfile(str(src), str(dst))
else: