@@ -356,14 +356,23 @@ def bottom_layer(self):
356356 """
357357 return self .layers [0 ]
358358
359- def extract_layers (self , extracted_location ):
359+ def extract_layers (self , extracted_location , as_events = False , skip_symlinks = True ):
360360 """
361361 Extract all layer archives to the `extracted_location` directory.
362362 Each layer is extracted to its own directory named after its `layer_id`.
363+ Skip symlinks and links if ``skip_symlinks`` is True.
364+ Return a list of ExtractEvent if ``as_events`` is True or a list of message strings otherwise.
363365 """
366+ all_events = []
364367 for layer in self .layers :
365368 exloc = os .path .join (extracted_location , layer .layer_id )
366- layer .extract (extracted_location = exloc )
369+ events = layer .extract (
370+ extracted_location = exloc ,
371+ skip_symlinks = skip_symlinks ,
372+ as_events = as_events ,
373+ )
374+ all_events .extend (events )
375+ return events
367376
368377 def get_layers_resources (self , with_dir = False ):
369378 """
@@ -450,41 +459,53 @@ def get_installed_packages(self, packages_getter):
450459 yield purl , package , layer
451460
452461 @staticmethod
453- def extract (archive_location , extracted_location , skip_symlinks = False ):
462+ def extract (archive_location , extracted_location , as_events = False , skip_symlinks = False ):
454463 """
455464 Extract the image archive tarball at ``archive_location`` to
456- ``extracted_location``. Skip symlinks and links if ``skip_symlinks`` is True.
465+ ``extracted_location``.
466+ Skip symlinks and links if ``skip_symlinks`` is True.
467+ Return a list of ExtractEvent if ``as_events`` is True or a list of message strings otherwise.
457468 """
458- utils .extract_tar (
469+ return utils .extract_tar (
459470 location = archive_location ,
460471 target_dir = extracted_location ,
461472 skip_symlinks = skip_symlinks ,
473+ as_events = as_events ,
462474 )
463475
464476 @staticmethod
465477 def get_images_from_tarball (
466478 archive_location ,
467479 extracted_location ,
468480 verify = True ,
481+ skip_symlinks = False ,
469482 ):
470483 """
471- Return a list of Images found in the tarball at `archive_location` that
472- will be extracted to `extracted_location`. The tarball must be in the
484+ Return a list of Images found in the tarball at `` archive_location` ` that
485+ will be extracted to `` extracted_location` `. The tarball must be in the
473486 format of a "docker save" command tarball.
474487
475- If `verify` is True, perform extra checks on the config data and layers
488+ If `` verify` ` is True, perform extra checks on the config data and layers
476489 checksums.
490+ Skip symlinks and links if ``skip_symlinks`` is True.
491+ Ignore the extract events from extraction.
477492 """
478493 if TRACE :
479494 logger .debug (
480- f'get_images_from_tarball: { archive_location } , '
495+ f'get_images_from_tarball: { archive_location } '
481496 f'extracting to: { extracted_location } '
482497 )
483498
484- Image .extract (
499+ # TODO: do not ignore extract events
500+ _events = Image .extract (
485501 archive_location = archive_location ,
486502 extracted_location = extracted_location ,
503+ skip_symlinks = skip_symlinks ,
487504 )
505+ if TRACE :
506+ logger .debug (f'get_images_from_tarball: events' )
507+ for e in _events :
508+ logger .debug (str (e ))
488509
489510 return Image .get_images_from_dir (
490511 extracted_location = extracted_location ,
@@ -1071,16 +1092,19 @@ def __attrs_post_init__(self, *args, **kwargs):
10711092 if not self .size :
10721093 self .size = os .path .getsize (self .archive_location )
10731094
1074- def extract (self , extracted_location , skip_symlinks = True ):
1095+ def extract (self , extracted_location , as_events = False , skip_symlinks = False ):
10751096 """
10761097 Extract this layer archive in the `extracted_location` directory and set
10771098 this Layer ``extracted_location`` attribute to ``extracted_location``.
1099+ Skip symlinks and links if ``skip_symlinks`` is True.
1100+ Return a list of ExtractEvent if ``as_events`` is True or a list of message strings otherwise.
10781101 """
10791102 self .extracted_location = extracted_location
1080- utils .extract_tar (
1103+ return utils .extract_tar (
10811104 location = self .archive_location ,
10821105 target_dir = extracted_location ,
10831106 skip_symlinks = skip_symlinks ,
1107+ as_events = as_events ,
10841108 )
10851109
10861110 def get_resources (self , with_dir = False , walker = os .walk ):
0 commit comments