Skip to content

Commit

Permalink
Set ZIP strict_timestamps to false (ansible#1049)
Browse files Browse the repository at this point in the history
* Set ZIP strict_timestamps to false

Since python 3.8 timestamps before 1980 are disallowed by default,
but seem to occur in streams.

Fixes: awx#12126

Signed-off-by: Björn Pedersen <bjoern.pedersen@frm2.tum.de>

* Add test for timestamps before 1980

Co-authored-by: Alan Rominger <arominge@redhat.com>
(cherry picked from commit ec5997e)
  • Loading branch information
bpedersen2 authored and Shrews committed May 4, 2022
1 parent c66f0c9 commit b1d022e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ansible_runner/utils/streaming.py
Expand Up @@ -13,7 +13,7 @@
def stream_dir(source_directory, stream):
with tempfile.NamedTemporaryFile() as tmp:
with zipfile.ZipFile(
tmp.name, "w", compression=zipfile.ZIP_DEFLATED, allowZip64=True
tmp.name, "w", compression=zipfile.ZIP_DEFLATED, allowZip64=True, strict_timestamps=False
) as archive:
if source_directory:
for dirpath, dirs, files in os.walk(source_directory):
Expand Down
23 changes: 23 additions & 0 deletions test/unit/utils/test_utils.py
Expand Up @@ -194,6 +194,29 @@ def test_transmit_modtimes(tmp_path):
assert old_delta >= datetime.timedelta(days=1).total_seconds() - 2.


def test_transmit_file_from_before_1980s(tmp_path):
source_dir = tmp_path / 'source'
source_dir.mkdir()

old_file = source_dir / 'cassette_tape.txt'
old_file.touch()

old_timestamp = datetime.datetime(year=1978, month=7, day=28).timestamp()
os.utime(old_file, (old_timestamp, old_timestamp))

outgoing_buffer = io.BytesIO()
outgoing_buffer.name = 'not_stdout'
stream_dir(source_dir, outgoing_buffer)

dest_dir = tmp_path / 'dest'
dest_dir.mkdir()

outgoing_buffer.seek(0)
first_line = outgoing_buffer.readline()
size_data = json.loads(first_line.strip())
unstream_dir(outgoing_buffer, size_data['zipfile'], dest_dir)


def test_signal_handler(mocker):
"""Test the default handler is set to handle the correct signals"""

Expand Down

0 comments on commit b1d022e

Please sign in to comment.