mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 22:51:23 -07:00
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
This commit is contained in:
parent
8414230266
commit
529ef6446e
2 changed files with 34 additions and 14 deletions
|
@ -132,6 +132,7 @@ EXAMPLES = r'''
|
||||||
import binascii
|
import binascii
|
||||||
import codecs
|
import codecs
|
||||||
import datetime
|
import datetime
|
||||||
|
import fnmatch
|
||||||
import grp
|
import grp
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
@ -263,7 +264,11 @@ class ZipArchive(object):
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
for member in archive.namelist():
|
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))
|
self._files_in_archive.append(to_native(member))
|
||||||
except:
|
except:
|
||||||
archive.close()
|
archive.close()
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
# Make sure we start fresh
|
# 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)
|
- name: Ensure zip and unzip is present to create test archive (yum)
|
||||||
yum: name=zip,unzip state=latest
|
yum: name=zip,unzip state=latest
|
||||||
when: ansible_pkg_mgr == 'yum'
|
when: ansible_pkg_mgr == 'yum'
|
||||||
|
@ -26,11 +26,11 @@
|
||||||
# dnf: name=zip state=latest
|
# dnf: name=zip state=latest
|
||||||
# when: ansible_pkg_mgr == 'dnf'
|
# 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
|
apt: name=zip,unzip state=latest
|
||||||
when: ansible_pkg_mgr == 'apt'
|
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
|
pkgng: name=zip,unzip state=present
|
||||||
when: ansible_pkg_mgr == 'pkgng'
|
when: ansible_pkg_mgr == 'pkgng'
|
||||||
|
|
||||||
|
@ -184,6 +184,26 @@
|
||||||
that:
|
that:
|
||||||
- "unarchive03b.changed == false"
|
- "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
|
- name: remove our zip unarchive destination
|
||||||
file: path={{output_dir}}/test-unarchive-zip state=absent
|
file: path={{output_dir}}/test-unarchive-zip state=absent
|
||||||
|
|
||||||
|
@ -251,7 +271,6 @@
|
||||||
- name: create our unarchive destination
|
- name: create our unarchive destination
|
||||||
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
||||||
|
|
||||||
|
|
||||||
- name: unarchive over existing extraction and set mode to 0644
|
- name: unarchive over existing extraction and set mode to 0644
|
||||||
unarchive:
|
unarchive:
|
||||||
src: "{{ output_dir }}/test-unarchive.tar.gz"
|
src: "{{ output_dir }}/test-unarchive.tar.gz"
|
||||||
|
@ -293,7 +312,6 @@
|
||||||
- name: remove our tar.gz unarchive destination
|
- name: remove our tar.gz unarchive destination
|
||||||
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
|
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
|
||||||
|
|
||||||
|
|
||||||
- name: create our unarchive destination
|
- name: create our unarchive destination
|
||||||
file: path={{output_dir}}/test-unarchive-zip state=directory
|
file: path={{output_dir}}/test-unarchive-zip state=directory
|
||||||
|
|
||||||
|
@ -358,11 +376,9 @@
|
||||||
- name: remove our zip unarchive destination
|
- name: remove our zip unarchive destination
|
||||||
file: path={{ output_dir }}/test-unarchive-zip state=absent
|
file: path={{ output_dir }}/test-unarchive-zip state=absent
|
||||||
|
|
||||||
|
|
||||||
- name: create our unarchive destination
|
- name: create our unarchive destination
|
||||||
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
||||||
|
|
||||||
|
|
||||||
- name: create a directory with quotable chars
|
- name: create a directory with quotable chars
|
||||||
file: path="{{ output_dir }}/test-quotes~root" state=directory
|
file: path="{{ output_dir }}/test-quotes~root" state=directory
|
||||||
|
|
||||||
|
@ -503,7 +519,6 @@
|
||||||
- name: remove our tar.gz unarchive destination
|
- name: remove our tar.gz unarchive destination
|
||||||
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
|
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
|
||||||
|
|
||||||
|
|
||||||
- name: Create a file
|
- name: Create a file
|
||||||
file:
|
file:
|
||||||
path: "{{ output_dir }}/test-unarchive-tar-gz"
|
path: "{{ output_dir }}/test-unarchive-tar-gz"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue