Allow find to be limited to max_matches.

pull/83153/head
Colin Nolan 1 month ago
parent 802e95f580
commit d75cebb1f8

@ -467,7 +467,8 @@ def main():
depth=dict(type='int'),
mode=dict(type='raw'),
exact_mode=dict(type='bool', default=True),
encoding=dict(type='str')
encoding=dict(type='str'),
max_matches=dict(type='int', default=-1)
),
supports_check_mode=True,
)
@ -520,6 +521,11 @@ def main():
else:
module.fail_json(size=params['size'], msg="failed to process size")
if params['max_matches'] == 0:
module.fail_json(msg="max_matches cannot be 0 (use -1 for unlimited)")
elif params['max_matches'] < -1:
module.fail_json(msg="max_matches cannot be %d (use -1 for unlimited)" % params['max_matches'])
now = time.time()
msg = 'All paths examined'
looked = 0
@ -596,7 +602,7 @@ def main():
r.update(statinfo(st))
filelist.append(r)
if not params['recurse']:
if not params['recurse'] or len(filelist) == params["max_matches"]:
break
except Exception as e:
skipped[npath] = to_text(e)

Loading…
Cancel
Save