summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2019-12-21 16:50:15 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2019-12-23 18:36:56 -0800
commit9b90d7e801c226a061e5b1e3e70bf2967f3ef6f1 (patch)
treeb6d3b64d9605551ee943a2fdd6b7ec85d1d3f258 /lib
parentc83e365c5931f6421c0d0cdcd4967010406c3622 (diff)
downloadspack-9b90d7e801c226a061e5b1e3e70bf2967f3ef6f1.tar.gz
spack-9b90d7e801c226a061e5b1e3e70bf2967f3ef6f1.tar.bz2
spack-9b90d7e801c226a061e5b1e3e70bf2967f3ef6f1.tar.xz
spack-9b90d7e801c226a061e5b1e3e70bf2967f3ef6f1.zip
performance: reduce system calls required for remove_dead_links
`os.path.exists()` will report False if the target of a symlink doesn't exist, so we can avoid a costly call to realpath here.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/llnl/util/filesystem.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index 4bdf543d79..e9dd88ffdb 100644
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -917,10 +917,8 @@ def remove_if_dead_link(path):
Parameters:
path (str): The potential dead link
"""
- if os.path.islink(path):
- real_path = os.path.realpath(path)
- if not os.path.exists(real_path):
- os.unlink(path)
+ if os.path.islink(path) and not os.path.exists(path):
+ os.unlink(path)
def remove_linked_tree(path):