mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-24 23:21:17 +02:00
Treat packages with missing SHA1 as not duplicated.
TBR=Needed to fix preflight build. BUG=chromium-os:5311 TEST=Remove SHA1 from one of the packages in the Packages file, make sure that prebuilt.py treats that as a duplicated package. Also run new unit tests. Also ran buildbot.py Change-Id: Ie35a7c818fd659bcc2296605ace850aee2a88448 Review URL: http://codereview.chromium.org/5370005
This commit is contained in:
parent
74f0f17ad8
commit
adcb314d9f
@ -51,9 +51,10 @@ class PackageIndex(object):
|
||||
|
||||
uri = self.header['URI']
|
||||
for pkg in self.packages:
|
||||
cpv, sha1 = pkg['CPV'], pkg['SHA1']
|
||||
path = pkg.get('PATH', cpv + '.tbz2')
|
||||
db[sha1] = urlparse.urljoin(uri, path)
|
||||
cpv, sha1 = pkg['CPV'], pkg.get('SHA1')
|
||||
if sha1:
|
||||
path = pkg.get('PATH', cpv + '.tbz2')
|
||||
db[sha1] = urlparse.urljoin(uri, path)
|
||||
|
||||
def _ReadPkgIndex(self, pkgfile):
|
||||
"""Read a list of key/value pairs from the Packages file into a dictionary.
|
||||
@ -180,9 +181,9 @@ class PackageIndex(object):
|
||||
uploads = []
|
||||
base_uri = self.header['URI']
|
||||
for pkg in self.packages:
|
||||
sha1 = pkg['SHA1']
|
||||
sha1 = pkg.get('SHA1')
|
||||
uri = db.get(sha1)
|
||||
if uri and uri.startswith(base_uri):
|
||||
if sha1 and uri and uri.startswith(base_uri):
|
||||
pkg['PATH'] = uri[len(base_uri):].lstrip('/')
|
||||
else:
|
||||
uploads.append(pkg)
|
||||
|
@ -221,6 +221,15 @@ class TestPopulateDuplicateDB(unittest.TestCase):
|
||||
self.assertEqual(db['2'], 'http://www.example.com/foo.tgz')
|
||||
self.assertEqual(db['3'], 'http://www.example.com/private.tbz2')
|
||||
|
||||
def testMissingSHA1(self):
|
||||
db = {}
|
||||
pkgindex = SimplePackageIndex()
|
||||
del pkgindex.packages[0]['SHA1']
|
||||
pkgindex._PopulateDuplicateDB(db)
|
||||
self.assertEqual(len(db), 2)
|
||||
self.assertEqual(db['2'], 'http://www.example.com/foo.tgz')
|
||||
self.assertEqual(db['3'], 'http://www.example.com/private.tbz2')
|
||||
|
||||
def testFailedPopulate(self):
|
||||
db = {}
|
||||
pkgindex = SimplePackageIndex(header=False)
|
||||
@ -228,9 +237,6 @@ class TestPopulateDuplicateDB(unittest.TestCase):
|
||||
pkgindex = SimplePackageIndex()
|
||||
del pkgindex.packages[0]['CPV']
|
||||
self.assertRaises(KeyError, pkgindex._PopulateDuplicateDB, db)
|
||||
pkgindex = SimplePackageIndex()
|
||||
del pkgindex.packages[0]['SHA1']
|
||||
self.assertRaises(KeyError, pkgindex._PopulateDuplicateDB, db)
|
||||
|
||||
|
||||
class TestResolveDuplicateUploads(unittest.TestCase):
|
||||
@ -261,6 +267,18 @@ class TestResolveDuplicateUploads(unittest.TestCase):
|
||||
uploads = pkgindex.ResolveDuplicateUploads([dup_pkgindex])
|
||||
self.assertEqual(pkgindex.packages, expected_pkgindex.packages)
|
||||
|
||||
def testMissingSHA1(self):
|
||||
db = {}
|
||||
pkgindex = SimplePackageIndex()
|
||||
dup_pkgindex = SimplePackageIndex()
|
||||
expected_pkgindex = SimplePackageIndex()
|
||||
del pkgindex.packages[0]['SHA1']
|
||||
del expected_pkgindex.packages[0]['SHA1']
|
||||
for pkg in expected_pkgindex.packages[1:]:
|
||||
pkg.setdefault('PATH', pkg['CPV'] + '.tbz2')
|
||||
uploads = pkgindex.ResolveDuplicateUploads([dup_pkgindex])
|
||||
self.assertEqual(pkgindex.packages, expected_pkgindex.packages)
|
||||
|
||||
|
||||
class TestWritePackageIndex(unittest.TestCase):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user