|
6 | 6 | from six import PY2, with_metaclass
|
7 | 7 |
|
8 | 8 | import hashlib
|
| 9 | +from re import match |
9 | 10 |
|
10 | 11 | import sh
|
11 | 12 | import shutil
|
@@ -349,51 +350,58 @@ def download(self):
|
349 | 350 | return
|
350 | 351 |
|
351 | 352 | url = self.versioned_url
|
| 353 | + ma = match(u'^(.+)#md5=([0-9a-f]{32})$', url) |
| 354 | + if ma: # fragmented URL? |
| 355 | + if self.md5sum: |
| 356 | + raise ValueError( |
| 357 | + ('Received md5sum from both the {} recipe ' |
| 358 | + 'and its url').format(self.name)) |
| 359 | + url = ma.group(1) |
| 360 | + expected_md5 = ma.group(2) |
| 361 | + else: |
| 362 | + expected_md5 = self.md5sum |
352 | 363 |
|
353 | 364 | shprint(sh.mkdir, '-p', join(self.ctx.packages_path, self.name))
|
354 | 365 |
|
355 | 366 | with current_directory(join(self.ctx.packages_path, self.name)):
|
356 | 367 | filename = shprint(sh.basename, url).stdout[:-1].decode('utf-8')
|
357 | 368 |
|
358 | 369 | do_download = True
|
359 |
| - |
360 | 370 | marker_filename = '.mark-{}'.format(filename)
|
361 | 371 | if exists(filename) and isfile(filename):
|
362 | 372 | if not exists(marker_filename):
|
363 | 373 | shprint(sh.rm, filename)
|
364 |
| - elif self.md5sum: |
| 374 | + elif expected_md5: |
365 | 375 | current_md5 = md5sum(filename)
|
366 |
| - if current_md5 == self.md5sum: |
367 |
| - debug('Checked md5sum: downloaded expected content!') |
368 |
| - do_download = False |
369 |
| - else: |
370 |
| - info('Downloaded unexpected content...') |
| 376 | + if current_md5 != expected_md5: |
371 | 377 | debug('* Generated md5sum: {}'.format(current_md5))
|
372 |
| - debug('* Expected md5sum: {}'.format(self.md5sum)) |
373 |
| - |
| 378 | + debug('* Expected md5sum: {}'.format(expected_md5)) |
| 379 | + raise ValueError( |
| 380 | + ('Generated md5sum does not match expected md5sum ' |
| 381 | + 'for {} recipe').format(self.name)) |
| 382 | + do_download = False |
374 | 383 | else:
|
375 | 384 | do_download = False
|
376 |
| - info('{} download already cached, skipping' |
377 |
| - .format(self.name)) |
378 | 385 |
|
379 | 386 | # If we got this far, we will download
|
380 | 387 | if do_download:
|
381 | 388 | debug('Downloading {} from {}'.format(self.name, url))
|
382 | 389 |
|
383 | 390 | shprint(sh.rm, '-f', marker_filename)
|
384 |
| - self.download_file(url, filename) |
| 391 | + self.download_file(self.versioned_url, filename) |
385 | 392 | shprint(sh.touch, marker_filename)
|
386 | 393 |
|
387 |
| - if exists(filename) and isfile(filename) and self.md5sum: |
| 394 | + if exists(filename) and isfile(filename) and expected_md5: |
388 | 395 | current_md5 = md5sum(filename)
|
389 |
| - if self.md5sum is not None: |
390 |
| - if current_md5 == self.md5sum: |
391 |
| - debug('Checked md5sum: downloaded expected content!') |
392 |
| - else: |
393 |
| - info('Downloaded unexpected content...') |
| 396 | + if expected_md5 is not None: |
| 397 | + if current_md5 != expected_md5: |
394 | 398 | debug('* Generated md5sum: {}'.format(current_md5))
|
395 |
| - debug('* Expected md5sum: {}'.format(self.md5sum)) |
396 |
| - exit(1) |
| 399 | + debug('* Expected md5sum: {}'.format(expected_md5)) |
| 400 | + raise ValueError( |
| 401 | + ('Generated md5sum does not match expected md5sum ' |
| 402 | + 'for {} recipe').format(self.name)) |
| 403 | + else: |
| 404 | + info('{} download already cached, skipping'.format(self.name)) |
397 | 405 |
|
398 | 406 | def unpack(self, arch):
|
399 | 407 | info_main('Unpacking {} for {}'.format(self.name, arch))
|
@@ -421,6 +429,9 @@ def unpack(self, arch):
|
421 | 429 |
|
422 | 430 | filename = shprint(
|
423 | 431 | sh.basename, self.versioned_url).stdout[:-1].decode('utf-8')
|
| 432 | + ma = match(u'^(.+)#md5=([0-9a-f]{32})$', filename) |
| 433 | + if ma: # fragmented URL? |
| 434 | + filename = ma.group(1) |
424 | 435 |
|
425 | 436 | with current_directory(build_dir):
|
426 | 437 | directory_name = self.get_build_dir(arch)
|
|
0 commit comments