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.
This commit is contained in:
Todd Gamblin 2019-12-21 16:50:15 -08:00
parent 79ddf6cf0d
commit f013687397
No known key found for this signature in database
GPG Key ID: 66B24B9050FDD0B8

View File

@ -917,9 +917,7 @@ 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):
if os.path.islink(path) and not os.path.exists(path):
os.unlink(path)