summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn W. Parent <45471568+johnwparent@users.noreply.github.com>2023-03-17 13:19:32 -0400
committerGitHub <noreply@github.com>2023-03-17 10:19:32 -0700
commit8195f27a661846311eae8412f8b8b3f0f0c2d368 (patch)
tree205c0c3f6fe8c15b19a3a078034c6b57ae001503
parenta60fa7ff7daba493fd8e5482be99d4cbeba4fdef (diff)
downloadspack-8195f27a661846311eae8412f8b8b3f0f0c2d368.tar.gz
spack-8195f27a661846311eae8412f8b8b3f0f0c2d368.tar.bz2
spack-8195f27a661846311eae8412f8b8b3f0f0c2d368.tar.xz
spack-8195f27a661846311eae8412f8b8b3f0f0c2d368.zip
Windows: properly handle symlink failures (#36003)
In the Windows filesystem logic for creating a symlink, we intend to fall back to a copy when the symlink cannot be created (for some configuration settings on Windows it is not possible for the user to create a symlink). It turns out we were overly-broad in which exceptions lead to this fallback, and the subsequent copy would also fail: at least one case where this occurred is when we attempted to create a symlink that already existed. The updated logic expressly avoids falling back to a copy when the file/symlink already exists.
-rw-r--r--lib/spack/llnl/util/filesystem.py2
-rw-r--r--lib/spack/llnl/util/symlink.py12
2 files changed, 10 insertions, 4 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index 889791d310..8af2f28342 100644
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -2407,7 +2407,7 @@ class WindowsSimulatedRPath(object):
# For py2 compatibility, we have to catch the specific Windows error code
# associate with trying to create a file that already exists (winerror 183)
except OSError as e:
- if sys.platform == "win32" and e.winerror == 183:
+ if sys.platform == "win32" and (e.winerror == 183 or e.errno == errno.EEXIST):
# We have either already symlinked or we are encoutering a naming clash
# either way, we don't want to overwrite existing libraries
already_linked = islink(dest_file)
diff --git a/lib/spack/llnl/util/symlink.py b/lib/spack/llnl/util/symlink.py
index 10616adfe8..69aacaf9f0 100644
--- a/lib/spack/llnl/util/symlink.py
+++ b/lib/spack/llnl/util/symlink.py
@@ -30,9 +30,15 @@ def symlink(real_path, link_path):
try:
# Try to use junctions
_win32_junction(real_path, link_path)
- except OSError:
- # If all else fails, fall back to copying files
- shutil.copyfile(real_path, link_path)
+ except OSError as e:
+ if e.errno == errno.EEXIST:
+ # EEXIST error indicates that file we're trying to "link"
+ # is already present, don't bother trying to copy which will also fail
+ # just raise
+ raise
+ else:
+ # If all else fails, fall back to copying files
+ shutil.copyfile(real_path, link_path)
def islink(path):