copy file data into a temporary file in openRemoteFile()

This commit is contained in:
Mike Bonnet 2010-10-25 11:17:05 -04:00
parent 3bcbfa3b3d
commit d6fdacd507
2 changed files with 9 additions and 10 deletions

View file

@ -532,9 +532,7 @@ class BuildRoot(object):
#at this point we know there were external repos at the create event,
#so there should be an origins file.
origin_idx = {}
#GzipFile doesn't play nice with urlopen, so we have the following
fo2 = GzipFile(fileobj=StringIO(fo.read()), mode='r')
fo.close()
fo2 = GzipFile(fileobj=fo, mode='r')
for line in fo2:
parts=line.split(None, 2)
if len(parts) < 2:
@ -543,6 +541,7 @@ class BuildRoot(object):
nvra = "%(name)s-%(version)s-%(release)s.%(arch)s" % koji.parse_NVRA(parts[0])
origin_idx[nvra] = parts[1]
fo2.close()
fo.close()
# mergerepo starts from a local repo in the task workdir, so internal
# rpms have an odd-looking origin that we need to look for
localtail = '/repo_%s_premerge/' % self.repo_info['id']
@ -774,6 +773,7 @@ class BuildTask(BaseTaskHandler):
opts = dict([(k, getattr(self.options, k)) for k in 'topurl','topdir'])
fo = koji.openRemoteFile(relpath, **opts)
h = koji.get_rpm_header(fo)
fo.close()
if h[rpm.RPMTAG_SOURCEPACKAGE] != 1:
raise koji.BuildError, "%s is not a source package" % srpm
return h

View file

@ -38,6 +38,7 @@ import pwd
import random
import re
import rpm
import shutil
import signal
import socket
import struct
@ -1364,13 +1365,11 @@ def openRemoteFile(relpath, topurl=None, topdir=None):
on options"""
if topurl:
url = "%s/%s" % (topurl, relpath)
fo = urllib2.urlopen(url)
# horrible hack because urlopen() returns a wrapped HTTPConnection
# object which doesn't implement fileno()
def urlopen_fileno(fileobj):
return lambda: fileobj.fp._sock.fp.fileno()
fo.fileno = urlopen_fileno(fo)
src = urllib2.urlopen(url)
fo = tempfile.TemporaryFile()
shutil.copyfileobj(src, fo)
src.close()
fo.seek(0)
elif topdir:
fn = "%s/%s" % (topdir, relpath)
fo = open(fn)