summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSloane Hertel <19572925+s-hertel@users.noreply.github.com>2021-02-25 14:32:49 -0500
committerGitHub <noreply@github.com>2021-02-26 05:32:49 +1000
commit8628c12f30693e520b6c7bcb816bbcbbbe0cd5bb (patch)
tree7bbee32cd3de11588a094657d0e32816d4984bbb /lib
parent950ab74758a6014639236612594118b2b6f4751e (diff)
downloadansible-8628c12f30693e520b6c7bcb816bbcbbbe0cd5bb.tar.gz
find module - stop traversing directories with os.walk when depth is already exceeded (#73718)
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/modules/find.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/ansible/modules/find.py b/lib/ansible/modules/find.py
index 04efff2384..323d0223f2 100644
--- a/lib/ansible/modules/find.py
+++ b/lib/ansible/modules/find.py
@@ -436,6 +436,8 @@ def main():
wpath = npath.rstrip(os.path.sep) + os.path.sep
depth = int(fsname.count(os.path.sep)) - int(wpath.count(os.path.sep)) + 1
if depth > params['depth']:
+ # Empty the list used by os.walk to avoid traversing deeper unnecessarily
+ del(dirs[:])
continue
if os.path.basename(fsname).startswith('.') and not params['hidden']:
continue