1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

archive - fix removal failures for nested files with tar archives (#2923) (#2927)

* Initial commit

* Adding changelog fragment

(cherry picked from commit ffe505a798)

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>
This commit is contained in:
patchback[bot] 2021-07-02 21:55:15 +02:00 committed by GitHub
parent 6d5dbfd455
commit 58d8469759
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 8 deletions

View file

@ -0,0 +1,4 @@
---
bugfixes:
- archive - fixed task failure when using the ``remove`` option with a ``path`` containing nested files for
``format``s other than ``zip`` (https://github.com/ansible-collections/community.general/issues/2919).

View file

@ -399,13 +399,14 @@ class Archive(object):
def remove_targets(self):
for path in self.successes:
try:
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.remove(path)
except OSError:
self.errors.append(_to_native(path))
if os.path.exists(path):
try:
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.remove(path)
except OSError:
self.errors.append(_to_native(path))
for path in self.paths:
try:
if os.path.isdir(path):

View file

@ -148,7 +148,39 @@
- name: verify that excluded sub file is still present
file: path={{ output_dir }}/tmpdir/sub/subfile.txt state=file
- name: remove temporary directory
- name: prep our files in tmpdir again
copy: src={{ item }} dest={{ output_dir }}/tmpdir/{{ item }}
with_items:
- foo.txt
- bar.txt
- empty.txt
- sub
- sub/subfile.txt
- name: archive using gz and remove src directory
archive:
path:
- "{{ output_dir }}/tmpdir/"
dest: "{{ output_dir }}/archive_remove_05.gz"
format: gz
remove: yes
exclude_path: "{{ output_dir }}/tmpdir/sub/subfile.txt"
register: archive_remove_result_05
- name: verify that the files archived
file: path={{ output_dir }}/archive_remove_05.gz state=file
- name: Verify source files were removed
file:
path: "{{ output_dir }}/tmpdir"
state: absent
register: archive_source_file_removal_05
- name: Verify that task status is success
assert:
that:
- archive_remove_result_05 is success
- archive_source_file_removal_05 is not changed
- name: remove our gz
file: path="{{ output_dir }}/archive_remove_05.gz" state=absent