Skip to content

Commit

Permalink
Changes as suggested by sivel
Browse files Browse the repository at this point in the history
  • Loading branch information
tachyontec committed Jun 7, 2023
1 parent 519caca commit 5e2cf9f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/ansible/plugins/action/include_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from os import path, walk
import re
import pathlib

import ansible.constants as C
from ansible.errors import AnsibleError
Expand Down Expand Up @@ -182,16 +183,15 @@ def _traverse_dir_depth(self):
alphabetical order. Do not iterate pass the set depth.
The default depth is unlimited.
"""
current_depth = 0
sorted_walk = list(walk(self.source_dir, onerror=self._log_walk, followlinks=True))
sorted_walk.sort(key=lambda x: x[0])
for current_root, current_dir, current_files in sorted_walk:
current_depth += 1
if current_depth <= self.depth or self.depth == 0:
current_files.sort()
yield (current_root, current_files)
else:
break
# Depth 1 is the root, relative_to omits the root
current_depth = len(pathlib.Path(current_root).relative_to(self.source_dir).parts) + 1
if self.depth != 0 and current_depth > self.depth:
continue
current_files.sort()
yield (current_root, current_files)

def _ignore_file(self, filename):
""" Return True if a file matches the list of ignore_files.
Expand Down

0 comments on commit 5e2cf9f

Please sign in to comment.