|
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,52 @@ 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 Exception('Recipe md5sum via fragmented URL only!') |
| 357 | + url = ma.group(1) |
| 358 | + expected_md5 = ma.group(2) |
| 359 | + else: |
| 360 | + expected_md5 = self.md5sum |
352 | 361 |
|
353 | 362 | shprint(sh.mkdir, '-p', join(self.ctx.packages_path, self.name))
|
354 | 363 |
|
355 | 364 | with current_directory(join(self.ctx.packages_path, self.name)):
|
356 | 365 | filename = shprint(sh.basename, url).stdout[:-1].decode('utf-8')
|
357 | 366 |
|
358 | 367 | do_download = True
|
359 |
| - |
360 | 368 | marker_filename = '.mark-{}'.format(filename)
|
361 | 369 | if exists(filename) and isfile(filename):
|
362 | 370 | if not exists(marker_filename):
|
363 | 371 | shprint(sh.rm, filename)
|
364 |
| - elif self.md5sum: |
| 372 | + elif expected_md5: |
365 | 373 | 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...') |
| 374 | + if current_md5 != expected_md5: |
371 | 375 | debug('* Generated md5sum: {}'.format(current_md5))
|
372 |
| - debug('* Expected md5sum: {}'.format(self.md5sum)) |
373 |
| - |
| 376 | + debug('* Expected md5sum: {}'.format(expected_md5)) |
| 377 | + raise Exception('Cached unexpected content!') |
| 378 | + do_download = False |
374 | 379 | else:
|
375 | 380 | do_download = False
|
376 |
| - info('{} download already cached, skipping' |
377 |
| - .format(self.name)) |
378 | 381 |
|
379 | 382 | # If we got this far, we will download
|
380 | 383 | if do_download:
|
381 | 384 | debug('Downloading {} from {}'.format(self.name, url))
|
382 | 385 |
|
383 | 386 | shprint(sh.rm, '-f', marker_filename)
|
384 |
| - self.download_file(url, filename) |
| 387 | + self.download_file(self.versioned_url, filename) |
385 | 388 | shprint(sh.touch, marker_filename)
|
386 | 389 |
|
387 |
| - if exists(filename) and isfile(filename) and self.md5sum: |
| 390 | + if exists(filename) and isfile(filename) and expected_md5: |
388 | 391 | 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...') |
| 392 | + if expected_md5 is not None: |
| 393 | + if current_md5 != expected_md5: |
394 | 394 | debug('* Generated md5sum: {}'.format(current_md5))
|
395 |
| - debug('* Expected md5sum: {}'.format(self.md5sum)) |
396 |
| - exit(1) |
| 395 | + debug('* Expected md5sum: {}'.format(expected_md5)) |
| 396 | + raise Exception('Downloaded unexpected content!') |
| 397 | + else: |
| 398 | + info('{} download already cached, skipping'.format(self.name)) |
397 | 399 |
|
398 | 400 | def unpack(self, arch):
|
399 | 401 | info_main('Unpacking {} for {}'.format(self.name, arch))
|
@@ -421,6 +423,9 @@ def unpack(self, arch):
|
421 | 423 |
|
422 | 424 | filename = shprint(
|
423 | 425 | sh.basename, self.versioned_url).stdout[:-1].decode('utf-8')
|
| 426 | + ma = match(u'^(.+)#md5=([0-9a-f]{32})$', filename) |
| 427 | + if ma: # fragmented URL? |
| 428 | + filename = ma.group(1) |
424 | 429 |
|
425 | 430 | with current_directory(build_dir):
|
426 | 431 | directory_name = self.get_build_dir(arch)
|
|
0 commit comments