Fix zip content filtering in unarchive module (#76069)

When we introduced an include parameter to the unarchive module, we
inadvertenly flipped the exclusion logic. This flip meant that the
unarchive module started rejecting files that should be extracted.

This commit flips the bad logic and adds some tests that will make
sure things do not go bad again.
pull/76184/head
Tadej Borovšak 3 years ago committed by GitHub
parent 173550f932
commit f92830d16e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
bugfixes:
- unarchive - Fix zip archive file listing that caused issues with content
postprocessing (https://github.com/ansible/ansible/issues/76067).

@ -386,7 +386,7 @@ class ZipArchive(object):
exclude_flag = False exclude_flag = False
if self.excludes: if self.excludes:
for exclude in self.excludes: for exclude in self.excludes:
if not fnmatch.fnmatch(member, exclude): if fnmatch.fnmatch(member, exclude):
exclude_flag = True exclude_flag = True
break break
if not exclude_flag: if not exclude_flag:

@ -11,13 +11,28 @@
src: "{{ remote_tmp_dir }}/unarchive-00.{{item}}" src: "{{ remote_tmp_dir }}/unarchive-00.{{item}}"
dest: "{{ remote_tmp_dir }}/exclude-{{item}}" dest: "{{ remote_tmp_dir }}/exclude-{{item}}"
remote_src: yes remote_src: yes
list_files: yes
exclude: exclude:
- "exclude/exclude-*.txt" - "exclude/exclude-*.txt"
- "other/exclude-1.ext" - "other/exclude-1.ext"
register: result_of_unarchive
with_items: with_items:
- zip - zip
- tar - tar
- name: Make sure unarchive module reported back extracted files
assert:
that:
- "'include/include-1.txt' in item.files"
- "'include/include-2.txt' in item.files"
- "'include/include-3.txt' in item.files"
- "'other/include-1.ext' in item.files"
- "'other/include-2.ext' in item.files"
- "'other/exclude-2.ext' in item.files"
- "'other/other-1.ext' in item.files"
- "'other/other-2.ext' in item.files"
loop: "{{ result_of_unarchive.results }}"
- name: verify that the file was unarchived - name: verify that the file was unarchived
shell: find {{ remote_tmp_dir }}/exclude-{{item}} chdir={{ remote_tmp_dir }} shell: find {{ remote_tmp_dir }}/exclude-{{item}} chdir={{ remote_tmp_dir }}
register: unarchive00 register: unarchive00

Loading…
Cancel
Save