summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlrrb <lrrb@users.noreply.github.com>2018-12-10 19:15:22 +0100
committerToshio Kuratomi <a.badger@gmail.com>2018-12-10 10:15:22 -0800
commit06ffe7b5d898ee147f2600bd3e9ad37bf0d59b2b (patch)
tree956b6fda80c3ff43addb57ecef48f8f459a3beef
parent5e0c292682052652821bd93d19501e533cfbd1a4 (diff)
downloadansible-06ffe7b5d898ee147f2600bd3e9ad37bf0d59b2b.tar.gz
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 4f9f1754b44aefd808536aeaf01262c84712659a) * added changelog
-rw-r--r--changelogs/fragments/45122-fix-unarchive-excluded_files.yaml2
-rw-r--r--lib/ansible/modules/files/unarchive.py17
-rw-r--r--test/integration/targets/unarchive/tasks/main.yml7
3 files changed, 18 insertions, 8 deletions
diff --git a/changelogs/fragments/45122-fix-unarchive-excluded_files.yaml b/changelogs/fragments/45122-fix-unarchive-excluded_files.yaml
new file mode 100644
index 0000000000..6b55bf0a21
--- /dev/null
+++ b/changelogs/fragments/45122-fix-unarchive-excluded_files.yaml
@@ -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"
diff --git a/lib/ansible/modules/files/unarchive.py b/lib/ansible/modules/files/unarchive.py
index 8a0bea8849..2e512d1ec7 100644
--- a/lib/ansible/modules/files/unarchive.py
+++ b/lib/ansible/modules/files/unarchive.py
@@ -264,11 +264,13 @@ class ZipArchive(object):
else:
try:
for member in archive.namelist():
+ exclude_flag = False
if self.excludes:
for exclude in self.excludes:
- if not fnmatch.fnmatch(member, exclude):
- self._files_in_archive.append(to_native(member))
- else:
+ if fnmatch.fnmatch(member, exclude):
+ exclude_flag = True
+ break
+ if not exclude_flag:
self._files_in_archive.append(to_native(member))
except:
archive.close()
@@ -664,11 +666,14 @@ class TgzArchive(object):
if filename.startswith('/'):
filename = filename[1:]
+ exclude_flag = False
if self.excludes:
for exclude in self.excludes:
- if not fnmatch.fnmatch(filename, exclude):
- self._files_in_archive.append(to_native(filename))
- else:
+ if fnmatch.fnmatch(filename, exclude):
+ exclude_flag = True
+ break
+
+ if not exclude_flag:
self._files_in_archive.append(to_native(filename))
return self._files_in_archive
diff --git a/test/integration/targets/unarchive/tasks/main.yml b/test/integration/targets/unarchive/tasks/main.yml
index 12cfcf10af..2d050f66a3 100644
--- a/test/integration/targets/unarchive/tasks/main.yml
+++ b/test/integration/targets/unarchive/tasks/main.yml
@@ -225,11 +225,13 @@
- zip
- tar
-- name: Unpack archive file excluding glob files.
+- name: Unpack archive file excluding regular and glob files.
unarchive:
src: "{{ output_dir }}/unarchive-00.{{item}}"
dest: "{{ output_dir }}/exclude-{{item}}"
- exclude: "exclude/exclude-*.txt"
+ exclude:
+ - "exclude/exclude-*.txt"
+ - "other/exclude-1.ext"
with_items:
- zip
- tar
@@ -245,6 +247,7 @@
assert:
that:
- "'exclude/exclude-1.txt' not in item.stdout"
+ - "'other/exclude-1.ext' not in item.stdout"
with_items:
- "{{ unarchive00.results }}"