@@ -190,7 +190,7 @@ def listfs(self, skip_partitions=('swap',)):
190190
191191 def extract_image (self , target_tarball ):
192192 """
193- Extract all files from this VM image in the `target_tarball` file as a
193+ Extract all files from this VM image in the `target_tarball` file as a
194194 gzipped-compressed tarball (.tar.gz). Raise exception on errors.
195195 """
196196 args = [
@@ -230,25 +230,36 @@ def run_guestfish(self, args, timeout=None):
230230 import subprocess
231231 full_args = [self .guestfish_command ] + args
232232 try :
233- stdout = subprocess .check_output (full_args , timeout = timeout , stderr = subprocess .STDOUT )
233+ stdout = subprocess .check_output (
234+ full_args ,
235+ timeout = timeout ,
236+ stderr = subprocess .STDOUT ,
237+ )
234238 except subprocess .CalledProcessError as cpe :
235239 args = ' ' .join ([self .guestfish_command ] + args )
236240 output = as_unicode (cpe .output )
237- error = f'Failed to run guestfish to extract VM image: { args } \n output: { output } '
238- raise ExtractErrorFailedToExtract (error ) # from cpe
241+ error = (
242+ f'Failed to run guestfish to extract VM image: { args } \n '
243+ f'output: { output } '
244+ )
245+ raise ExtractErrorFailedToExtract (error )
239246
240247 return as_unicode (stdout )
241248
242249
243- def extract (location , target_dir , as_tarballs = False ):
250+ def extract (location , target_dir , as_tarballs = False , skip_symlinks = True ):
244251 """
245252 Extract all files from a guestfish-supported VM image archive file at
246- location in the target_dir directory. Optionally only extract the
247- intermediate tarballs if `as_tarball` is True. Otherwise, extract to
248- intermediate tarballs and then extract each tarballs to the final directory.
249-
253+ location in the target_dir directory.
250254 Return a list of warning messages if any or an empty list.
255+
256+ Optionally only extract the intermediate tarballs if `as_tarball` is True.
257+ Otherwise, extract to intermediate tarballs and then extract each tarballs
258+ to the final directory.
259+
260+ Optionally skip extracting symlinks.
251261 Raise exception on errors.
262+
252263 This works only on Linux.
253264 """
254265 assert target_dir
@@ -280,7 +291,8 @@ def extract(location, target_dir, as_tarballs=False):
280291 warns = extract_image_tarball (
281292 tarball = target_tarball ,
282293 target_dir = target_dir ,
283- skip_symlinks = False )
294+ skip_symlinks = skip_symlinks ,
295+ )
284296 warnings .extend (warns )
285297
286298 except ExtractErrorFailedToExtract as e :
@@ -308,7 +320,8 @@ def extract(location, target_dir, as_tarballs=False):
308320 warns = extract_image_tarball (
309321 tarball = target_tarball ,
310322 target_dir = target_dir ,
311- skip_symlinks = False )
323+ skip_symlinks = skip_symlinks ,
324+ )
312325 warnings .extend (warns )
313326 else :
314327 # with multiple partitions, we extract each partition to a unique
@@ -333,7 +346,8 @@ def extract(location, target_dir, as_tarballs=False):
333346 warns = extract_image_tarball (
334347 tarball = target_tarball ,
335348 target_dir = partition_target_dir ,
336- skip_symlinks = False )
349+ skip_symlinks = skip_symlinks ,
350+ )
337351 warnings .extend (warns )
338352
339353 return warnings
0 commit comments