fix: Ensure zip excluded files are not checked (#40120)

* fix: Ensure zip excluded files are not checked

Fixes #26279

* test: Verify unarchive excludes behaves as expected

* fix: Typos and whitespaces
pull/39041/merge
Sijis Aviles 6 years ago committed by Adam Miller
parent 8414230266
commit 529ef6446e

@ -132,6 +132,7 @@ EXAMPLES = r'''
import binascii
import codecs
import datetime
import fnmatch
import grp
import os
import platform
@ -263,7 +264,11 @@ class ZipArchive(object):
else:
try:
for member in archive.namelist():
if member not in self.excludes:
if self.excludes:
for exclude in self.excludes:
if not fnmatch.fnmatch(member, exclude):
self._files_in_archive.append(to_native(member))
else:
self._files_in_archive.append(to_native(member))
except:
archive.close()

@ -17,7 +17,7 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make sure we start fresh
# Need unzup for unarchive module, and zip for archive creation.
# Need unzip for unarchive module, and zip for archive creation.
- name: Ensure zip and unzip is present to create test archive (yum)
yum: name=zip,unzip state=latest
when: ansible_pkg_mgr == 'yum'
@ -26,11 +26,11 @@
# dnf: name=zip state=latest
# when: ansible_pkg_mgr == 'dnf'
- name: Ensure zip & unzup is present to create test archive (apt)
- name: Ensure zip & unzip is present to create test archive (apt)
apt: name=zip,unzip state=latest
when: ansible_pkg_mgr == 'apt'
- name: Ensure zip & unzup is present to create test archive (pkg)
- name: Ensure zip & unzip is present to create test archive (pkg)
pkgng: name=zip,unzip state=present
when: ansible_pkg_mgr == 'pkgng'
@ -184,6 +184,26 @@
that:
- "unarchive03b.changed == false"
- name: "Create {{ output_dir }}/exclude directory"
file:
state: directory
path: "{{ output_dir }}/exclude"
- name: Unpack zip file excluding one file.
unarchive:
src: "{{ output_dir }}/test-unarchive.zip"
dest: "{{ output_dir }}/exclude"
exclude: "foo-unarchive-*.txt"
- name: verify that the file was unarchived
shell: find {{ output_dir }}/exclude chdir={{ output_dir }}
register: unarchive_dir01
- name: verify that zip extraction excluded file
assert:
that:
- "'foo-unarchive-777.txt' not in unarchive_dir01.stdout"
- name: remove our zip unarchive destination
file: path={{output_dir}}/test-unarchive-zip state=absent
@ -251,7 +271,6 @@
- name: create our unarchive destination
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
- name: unarchive over existing extraction and set mode to 0644
unarchive:
src: "{{ output_dir }}/test-unarchive.tar.gz"
@ -293,7 +312,6 @@
- name: remove our tar.gz unarchive destination
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
- name: create our unarchive destination
file: path={{output_dir}}/test-unarchive-zip state=directory
@ -358,11 +376,9 @@
- name: remove our zip unarchive destination
file: path={{ output_dir }}/test-unarchive-zip state=absent
- name: create our unarchive destination
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
- name: create a directory with quotable chars
file: path="{{ output_dir }}/test-quotes~root" state=directory
@ -503,7 +519,6 @@
- name: remove our tar.gz unarchive destination
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
- name: Create a file
file:
path: "{{ output_dir }}/test-unarchive-tar-gz"

Loading…
Cancel
Save