Fix endless loop in path existence check