Fix BadZipfile error while install msvc dependencies

This commit is contained in:
Learning 2019-01-19 22:27:16 +08:00
parent 7256d123ff
commit 9c1683bcef

View file

@ -12,6 +12,7 @@ import platform
import shutil
import subprocess
from subprocess import PIPE
from zipfile import BadZipfile
import servo.packages as packages
from servo.util import extract, download_file, host_triple
@ -300,6 +301,21 @@ def windows_msvc(context, force=False):
return True
return False
def prepare_file(zip_path, full_spec):
if not os.path.isfile(zip_path):
zip_url = "{}{}.zip".format(deps_url, full_spec)
download_file(full_spec, zip_url, zip_path)
print("Extracting {}...".format(full_spec), end='')
try:
extract(zip_path, deps_dir)
except BadZipfile:
print("\nError: %s.zip is not a valid zip file, redownload..." % full_spec)
os.remove(zip_path)
prepare_file(zip_path, full_spec)
else:
print("done")
to_install = {}
for package in packages.WINDOWS_MSVC:
# Don't install CMake if it already exists in PATH
@ -321,13 +337,7 @@ def windows_msvc(context, force=False):
os.makedirs(parent_dir)
zip_path = package_dir(package) + ".zip"
if not os.path.isfile(zip_path):
zip_url = "{}{}.zip".format(deps_url, full_spec)
download_file(full_spec, zip_url, zip_path)
print("Extracting {}...".format(full_spec), end='')
extract(zip_path, deps_dir)
print("done")
prepare_file(zip_path, full_spec)
extracted_path = os.path.join(deps_dir, full_spec)
os.rename(extracted_path, package_dir(package))