Skip to content
Snippets Groups Projects
Commit 8d02ec9c authored by Seblu's avatar Seblu
Browse files

improve tarball loading and check md5 from repository

parent f88c786c
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ import re
import shutil
import gzip
import gzipstream #until python support gzip not seekable
import cStringIO
import installsystems.template as istemplate
import installsystems.tools as istools
from installsystems.printer import *
......@@ -359,7 +360,12 @@ class PackageImage(Image):
try:
if fileobj is None:
fileobj = istools.uopen(self.path)
self._tarball = Tarball.open(fileobj=fileobj, mode='r:gz')
memfile = cStringIO.StringIO()
fileobj.seek(0)
(self.size, self.md5) = istools.copyfileobj(fileobj, memfile)
fileobj.close()
memfile.seek(0)
self._tarball = Tarball.open(fileobj=memfile, mode='r:gz')
except Exception as e:
raise Exception("Unable to open image %s: %s" % (path, e))
self._metadata = self.read_metadata()
......
......@@ -277,19 +277,23 @@ class Repository(object):
r = self.db.ask("select md5 from image where name = ? and version = ? limit 1",
(name, version)).fetchone()
if r is None:
raise Exception("Unable to find image %s version %s" % (name, version))
raise Exception("Unable to find image %s v%s" % (name, version))
path = os.path.join(self.config.path, r[0])
# getting the file
arrow("Loading image %s v%s from repository %s" % (name,
version,
self.config.name))
memfile = cStringIO.StringIO()
fo = istools.uopen(path)
(self.size, self.md5) = istools.copyfileobj(fo, memfile)
fo.close()
try:
fo = istools.uopen(path)
istools.copyfileobj(fo, memfile)
fo.close()
except Exception as e:
raise Exception("Loading image %s v%s failed: %s" % (name, version, e))
memfile.seek(0)
pkg = PackageImage(path, fileobj=memfile, md5name=True)
pkg.md5 = r[0]
if pkg.md5 != r[0]:
raise Exception("Image MD5 verification failure")
return pkg
def getmd5(self, name, version):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment