fix: Make sure that the files excluded when extracting the archive are not checked (#45122) (#49700)
* fix: ensure than all item of a list of excluded files aren't checked (#45122)
* fix: ensure than list of excluded files aren't checked
* test: exclude a list of files
(cherry picked from commit 4f9f1754b4
)
* added changelog
This commit is contained in:
parent
5e0c292682
commit
06ffe7b5d8
3 changed files with 18 additions and 8 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "Fixed: Make sure that the files excluded when extracting the archive are not checked. https://github.com/ansible/ansible/pull/45122"
|
|
@ -264,11 +264,13 @@ class ZipArchive(object):
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
for member in archive.namelist():
|
for member in archive.namelist():
|
||||||
|
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):
|
||||||
self._files_in_archive.append(to_native(member))
|
exclude_flag = True
|
||||||
else:
|
break
|
||||||
|
if not exclude_flag:
|
||||||
self._files_in_archive.append(to_native(member))
|
self._files_in_archive.append(to_native(member))
|
||||||
except:
|
except:
|
||||||
archive.close()
|
archive.close()
|
||||||
|
@ -664,11 +666,14 @@ class TgzArchive(object):
|
||||||
if filename.startswith('/'):
|
if filename.startswith('/'):
|
||||||
filename = filename[1:]
|
filename = filename[1:]
|
||||||
|
|
||||||
|
exclude_flag = False
|
||||||
if self.excludes:
|
if self.excludes:
|
||||||
for exclude in self.excludes:
|
for exclude in self.excludes:
|
||||||
if not fnmatch.fnmatch(filename, exclude):
|
if fnmatch.fnmatch(filename, exclude):
|
||||||
self._files_in_archive.append(to_native(filename))
|
exclude_flag = True
|
||||||
else:
|
break
|
||||||
|
|
||||||
|
if not exclude_flag:
|
||||||
self._files_in_archive.append(to_native(filename))
|
self._files_in_archive.append(to_native(filename))
|
||||||
|
|
||||||
return self._files_in_archive
|
return self._files_in_archive
|
||||||
|
|
|
@ -225,11 +225,13 @@
|
||||||
- zip
|
- zip
|
||||||
- tar
|
- tar
|
||||||
|
|
||||||
- name: Unpack archive file excluding glob files.
|
- name: Unpack archive file excluding regular and glob files.
|
||||||
unarchive:
|
unarchive:
|
||||||
src: "{{ output_dir }}/unarchive-00.{{item}}"
|
src: "{{ output_dir }}/unarchive-00.{{item}}"
|
||||||
dest: "{{ output_dir }}/exclude-{{item}}"
|
dest: "{{ output_dir }}/exclude-{{item}}"
|
||||||
exclude: "exclude/exclude-*.txt"
|
exclude:
|
||||||
|
- "exclude/exclude-*.txt"
|
||||||
|
- "other/exclude-1.ext"
|
||||||
with_items:
|
with_items:
|
||||||
- zip
|
- zip
|
||||||
- tar
|
- tar
|
||||||
|
@ -245,6 +247,7 @@
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "'exclude/exclude-1.txt' not in item.stdout"
|
- "'exclude/exclude-1.txt' not in item.stdout"
|
||||||
|
- "'other/exclude-1.ext' not in item.stdout"
|
||||||
with_items:
|
with_items:
|
||||||
- "{{ unarchive00.results }}"
|
- "{{ unarchive00.results }}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue