summaryrefslogtreecommitdiff
path: root/lib/spack/llnl/util/symlink.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/spack/llnl/util/symlink.py')
-rw-r--r--lib/spack/llnl/util/symlink.py41
1 files changed, 11 insertions, 30 deletions
diff --git a/lib/spack/llnl/util/symlink.py b/lib/spack/llnl/util/symlink.py
index 3e5f0d4868..d6e4651557 100644
--- a/lib/spack/llnl/util/symlink.py
+++ b/lib/spack/llnl/util/symlink.py
@@ -9,9 +9,11 @@ import tempfile
from os.path import exists, join
from sys import platform as _platform
-is_windows = _platform == 'win32'
+from llnl.util import lang
+
+from spack.util.executable import Executable
-__win32_can_symlink__ = None
+is_windows = _platform == 'win32'
def symlink(real_path, link_path):
@@ -51,21 +53,20 @@ def _win32_junction(path, link):
path = os.path.join(parent, path)
path = os.path.abspath(path)
+ command = "mklink"
+ default_args = [link, path]
if os.path.isdir(path):
# try using a junction
- command = 'mklink /J "%s" "%s"' % (link, path)
+ default_args.insert(0, '/J')
else:
# try using a hard link
- command = 'mklink /H "%s" "%s"' % (link, path)
+ default_args.insert(0, '/H')
- _cmd(command)
+ Executable(command)(*default_args)
+@lang.memoized
def _win32_can_symlink():
- global __win32_can_symlink__
- if __win32_can_symlink__ is not None:
- return __win32_can_symlink__
-
tempdir = tempfile.mkdtemp()
dpath = join(tempdir, 'dpath')
@@ -92,9 +93,7 @@ def _win32_can_symlink():
# Cleanup the test directory
shutil.rmtree(tempdir)
- __win32_can_symlink__ = can_symlink_directories and can_symlink_files
-
- return __win32_can_symlink__
+ return can_symlink_directories and can_symlink_files
def _win32_is_junction(path):
@@ -119,21 +118,3 @@ def _win32_is_junction(path):
bool(res & FILE_ATTRIBUTE_REPARSE_POINT)
return False
-
-
-# Based on https://github.com/Erotemic/ubelt/blob/master/ubelt/util_cmd.py
-def _cmd(command):
- import subprocess
-
- # Create a new process to execute the command
- def make_proc():
- # delay the creation of the process until we validate all args
- proc = subprocess.Popen(command, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, shell=True,
- universal_newlines=True, cwd=None, env=None)
- return proc
-
- proc = make_proc()
- (out, err) = proc.communicate()
- if proc.wait() != 0:
- raise OSError(str(err))