Added catch and clean of corrupt zip downloads
This commit is contained in:
parent
3f83bbffab
commit
73fd2357b2
1 changed files with 9 additions and 3 deletions
12
toolchain.py
12
toolchain.py
|
@ -9,7 +9,7 @@ This tool intend to replace all the previous tools/ in shell script.
|
||||||
import sys
|
import sys
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
from os.path import join, dirname, realpath, exists, isdir, basename
|
from os.path import join, dirname, realpath, exists, isdir, basename
|
||||||
from os import listdir, unlink, makedirs, environ, chdir, getcwd, walk
|
from os import listdir, unlink, makedirs, environ, chdir, getcwd, walk, remove
|
||||||
import zipfile
|
import zipfile
|
||||||
import tarfile
|
import tarfile
|
||||||
import importlib
|
import importlib
|
||||||
|
@ -410,8 +410,14 @@ class Recipe(object):
|
||||||
|
|
||||||
def get_archive_rootdir(self, filename):
|
def get_archive_rootdir(self, filename):
|
||||||
if filename.endswith(".tgz") or filename.endswith(".tar.gz") or \
|
if filename.endswith(".tgz") or filename.endswith(".tar.gz") or \
|
||||||
filename.endswith(".tbz2") or filename.endswith(".tar.bz2"):
|
filename.endswith(".tbz2") or filename.endswith(".tar.bz2"):
|
||||||
archive = tarfile.open(filename)
|
try:
|
||||||
|
archive = tarfile.open(filename)
|
||||||
|
except tarfile.ReadError:
|
||||||
|
print('Error extracting the archive {0}'.format(filename))
|
||||||
|
print('This is usually caused by a corrupt download. The file'
|
||||||
|
' will be removed and re-downloaded on the next run.')
|
||||||
|
remove(filename)
|
||||||
root = archive.next().path.split("/")
|
root = archive.next().path.split("/")
|
||||||
return root[0]
|
return root[0]
|
||||||
elif filename.endswith(".zip"):
|
elif filename.endswith(".zip"):
|
||||||
|
|
Loading…
Reference in a new issue