Added code to catch exception when ZIP file has invalid timestamp (#81092)

Fixes: #81092

Signed-off-by: gilsongpfe <gilson.gpf@gmail.com>
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/81520/head
gilsongpfe 10 months ago committed by Abhijeet Kasurde
parent 0bab08ee33
commit 47eb531491

@ -0,0 +1,3 @@
---
bugfixes:
- unarchive - catch exception when ZIP file has an invalid timestamp (https://github.com/ansible/ansible/issues/81092).

@ -601,8 +601,11 @@ class ZipArchive(object):
# Note: this timestamp calculation has a rounding error
# somewhere... unzip and this timestamp can be one second off
# When that happens, we report a change and re-unzip the file
dt_object = datetime.datetime(*(time.strptime(pcs[6], '%Y%m%d.%H%M%S')[0:6]))
timestamp = time.mktime(dt_object.timetuple())
try:
dt_object = datetime.datetime(*(time.strptime(pcs[6], '%Y%m%d.%H%M%S')[0:6]))
timestamp = time.mktime(dt_object.timetuple())
except ValueError as e:
self.module.exit_json(msg="Invalid timestamp: %s" % to_text(e), exception=traceback.format_exc())
# Compare file timestamps
if stat.S_ISREG(st.st_mode):

@ -21,3 +21,4 @@
- import_tasks: test_invalid_options.yml
- import_tasks: test_ownership_top_folder.yml
- import_tasks: test_relative_dest.yml
- import_tasks: test_zip_invalid_datetimestamp.yml

@ -0,0 +1,40 @@
- name: create our unarchive destination
file:
path: "{{ remote_tmp_dir }}/test_invalid"
state: directory
- name: test that unarchive works with an archive that contains file with invalid datetimestamp
unarchive:
src: "zip_with_invalid_datetimestamp.zip"
dest: "{{ remote_tmp_dir }}/test_invalid"
remote_src: no
register: invalid_result0
- name: Check that file is really there
stat:
path: "{{ remote_tmp_dir }}/test_invalid/eggs.txt"
register: invalid_stat0
- name: Assert that invalid zip tests succeeded
assert:
that:
- "invalid_result0.changed == true"
- "invalid_stat0.stat.exists == true"
- name: test that unarchive fails with an archive that contains file with invalid datetimestamp (idempotency)
unarchive:
src: "zip_with_invalid_datetimestamp.zip"
dest: "{{ remote_tmp_dir }}/test_invalid"
remote_src: no
register: invalid_result1
ignore_errors: true
- name: Assert that invalid zip tests succeeded
assert:
that:
- "invalid_result1.changed == false"
- name: remove invalid test directory
file:
path: "{{ remote_tmp_dir }}/test_invalid"
state: absent
Loading…
Cancel
Save