[bugfix][coverage] find module should consider file size with file_type=any (#74241)

* add changelog
* fix cl text
* Update changelogs/fragments/74241-find-checks-size-with-any.yml

Co-authored-by: Rick Elrod <rick@elrod.me>
This commit is contained in:
David Shrewsbury 2021-04-13 11:41:44 -04:00 committed by GitHub
parent fa0bccf6a1
commit 93fdba7013
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 121 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- find - fix a bug where ``size`` argument was ignored for regular files with ``file_type`` of ``any``.

View file

@ -466,7 +466,12 @@ def main():
r.update(statinfo(st)) r.update(statinfo(st))
if stat.S_ISREG(st.st_mode) and params['get_checksum']: if stat.S_ISREG(st.st_mode) and params['get_checksum']:
r['checksum'] = module.sha1(fsname) r['checksum'] = module.sha1(fsname)
filelist.append(r)
if stat.S_ISREG(st.st_mode):
if sizefilter(st, size):
filelist.append(r)
else:
filelist.append(r)
elif stat.S_ISDIR(st.st_mode) and params['file_type'] == 'directory': elif stat.S_ISDIR(st.st_mode) and params['file_type'] == 'directory':
if pfilter(fsobj, params['patterns'], params['excludes'], params['use_regex']) and agefilter(st, now, age, params['age_stamp']): if pfilter(fsobj, params['patterns'], params['excludes'], params['use_regex']) and agefilter(st, now, age, params['age_stamp']):

View file

@ -272,3 +272,116 @@
assert: assert:
that: that:
- '"{{ output_dir_test }}/e/f/g/h/8.ogg" not in find_test3_list' - '"{{ output_dir_test }}/e/f/g/h/8.ogg" not in find_test3_list'
- name: create our age/size testing sub-directory
file:
path: "{{ output_dir_test }}/astest"
state: directory
- name: create test file with old timestamps
file:
path: "{{ output_dir_test }}/astest/old.txt"
state: touch
modification_time: "202001011200.0"
- name: create test file with current timestamps
file:
path: "{{ output_dir_test }}/astest/new.txt"
state: touch
- name: create hidden test file with current timestamps
file:
path: "{{ output_dir_test }}/astest/.hidden.txt"
state: touch
- name: find files older than 1 week
find:
path: "{{ output_dir_test }}/astest"
age: 1w
hidden: true
register: result
- set_fact:
astest_list: >-
[ {% for f in result.files %}
{{ f.path }}
{% if not loop.last %},{% endif %}
{% endfor %}
]
- name: assert we only find the old file
assert:
that:
- result.matched == 1
- '"{{ output_dir_test }}/astest/old.txt" in astest_list'
- name: find files newer than 1 week
find:
path: "{{ output_dir_test }}/astest"
age: -1w
register: result
- set_fact:
astest_list: >-
[ {% for f in result.files %}
{{ f.path }}
{% if not loop.last %},{% endif %}
{% endfor %}
]
- name: assert we only find the current file
assert:
that:
- result.matched == 1
- '"{{ output_dir_test }}/astest/new.txt" in astest_list'
- name: add some content to the new file
shell: "echo hello world > {{ output_dir_test }}/astest/new.txt"
- name: find files with MORE than 5 bytes, also get checksums
find:
path: "{{ output_dir_test }}/astest"
size: 5
hidden: true
get_checksum: true
register: result
- set_fact:
astest_list: >-
[ {% for f in result.files %}
{{ f.path }}
{% if not loop.last %},{% endif %}
{% endfor %}
]
- name: assert we only find the hello world file
assert:
that:
- result.matched == 1
- '"{{ output_dir_test }}/astest/new.txt" in astest_list'
- '"checksum" in result.files[0]'
- name: find ANY item with LESS than 5 bytes, also get checksums
find:
path: "{{ output_dir_test }}/astest"
size: -5
hidden: true
get_checksum: true
file_type: any
register: result
- set_fact:
astest_list: >-
[ {% for f in result.files %}
{{ f.path }}
{% if not loop.last %},{% endif %}
{% endfor %}
]
- name: assert we do not find the hello world file and a checksum is present
assert:
that:
- result.matched == 2
- '"{{ output_dir_test }}/astest/old.txt" in astest_list'
- '"{{ output_dir_test }}/astest/.hidden.txt" in astest_list'
- '"checksum" in result.files[0]'