Skip to content

Commit

Permalink
Merge pull request #11 from yma88/master
Browse files Browse the repository at this point in the history
Fix to cath the BadZipFile error during unpacking
  • Loading branch information
yma96 authored Aug 8, 2023
2 parents 87e6da0 + 42489f7 commit 19668dd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sidecarinit/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
import os
from zipfile import ZipFile
from zipfile import BadZipFile

def download_archive(url, repository):
build_id = os.environ.get('BUILD_CONFIG_ID')
Expand All @@ -16,12 +17,15 @@ def download_archive(url, repository):
except urllib.error.HTTPError as e:
downloaded = False
if e.code == 404:
print("Archive not found\n")
print("Archive is not found.\n")
else:
print(f"{e.code}: {e.reason}\n\n{e.headers}")

if downloaded:
print(f"Archive successfully downloaded. Unpacking it in {repository}\n")
with ZipFile(repository + archive_path) as archive_zip:
archive_zip.extractall(repository)
print("Unpacked successfully\n")
print(f"Archive is downloaded successfully, unpacking it in {repository}\n")
try:
with ZipFile(repository + archive_path) as archive_zip:
archive_zip.extractall(repository)
print("Unpacked successfully.\n")
except BadZipFile:
print("Downloaded archive can not be extracted since it's a bad zip file.\n")

0 comments on commit 19668dd

Please sign in to comment.