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,10 +917,8 @@ def remove_if_dead_link(path):
Parameters: Parameters:
path (str): The potential dead link path (str): The potential dead link
""" """
if os.path.islink(path): if os.path.islink(path) and not os.path.exists(path):
real_path = os.path.realpath(path) os.unlink(path)
if not os.path.exists(real_path):
os.unlink(path)
def remove_linked_tree(path): def remove_linked_tree(path):