diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2019-12-21 16:50:15 -0800 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2019-12-23 23:18:46 -0800 |
commit | f01368739741ef9b3bcc827f7dbc2ab9d5b48df4 (patch) | |
tree | 660434f6e4927d51b4dac181bb2ea24704150df5 /lib | |
parent | 79ddf6cf0daa95ffef3aa1457b893bb245fa23de (diff) | |
download | spack-f01368739741ef9b3bcc827f7dbc2ab9d5b48df4.tar.gz spack-f01368739741ef9b3bcc827f7dbc2ab9d5b48df4.tar.bz2 spack-f01368739741ef9b3bcc827f7dbc2ab9d5b48df4.tar.xz spack-f01368739741ef9b3bcc827f7dbc2ab9d5b48df4.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.py | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 0095e3fd21..f6c8d161d7 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): |