@@ -190,7 +190,7 @@ def listfs(self, skip_partitions=('swap',)):
190
190
191
191
def extract_image (self , target_tarball ):
192
192
"""
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
194
194
gzipped-compressed tarball (.tar.gz). Raise exception on errors.
195
195
"""
196
196
args = [
@@ -230,25 +230,36 @@ def run_guestfish(self, args, timeout=None):
230
230
import subprocess
231
231
full_args = [self .guestfish_command ] + args
232
232
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
+ )
234
238
except subprocess .CalledProcessError as cpe :
235
239
args = ' ' .join ([self .guestfish_command ] + args )
236
240
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 )
239
246
240
247
return as_unicode (stdout )
241
248
242
249
243
- def extract (location , target_dir , as_tarballs = False ):
250
+ def extract (location , target_dir , as_tarballs = False , skip_symlinks = True ):
244
251
"""
245
252
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.
250
254
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.
251
261
Raise exception on errors.
262
+
252
263
This works only on Linux.
253
264
"""
254
265
assert target_dir
@@ -280,7 +291,8 @@ def extract(location, target_dir, as_tarballs=False):
280
291
warns = extract_image_tarball (
281
292
tarball = target_tarball ,
282
293
target_dir = target_dir ,
283
- skip_symlinks = False )
294
+ skip_symlinks = skip_symlinks ,
295
+ )
284
296
warnings .extend (warns )
285
297
286
298
except ExtractErrorFailedToExtract as e :
@@ -308,7 +320,8 @@ def extract(location, target_dir, as_tarballs=False):
308
320
warns = extract_image_tarball (
309
321
tarball = target_tarball ,
310
322
target_dir = target_dir ,
311
- skip_symlinks = False )
323
+ skip_symlinks = skip_symlinks ,
324
+ )
312
325
warnings .extend (warns )
313
326
else :
314
327
# with multiple partitions, we extract each partition to a unique
@@ -333,7 +346,8 @@ def extract(location, target_dir, as_tarballs=False):
333
346
warns = extract_image_tarball (
334
347
tarball = target_tarball ,
335
348
target_dir = partition_target_dir ,
336
- skip_symlinks = False )
349
+ skip_symlinks = skip_symlinks ,
350
+ )
337
351
warnings .extend (warns )
338
352
339
353
return warnings
0 commit comments