mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-09 10:34:58 -06:00
tests/functional: let cpio_extract accept filenames
Currently cpio_extract differs from tar_extract/zip_extract in that it only allows a file-like object as input. Adapt it to also support filenames. Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20241217155953.3950506-21-berrange@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
parent
512fe088b1
commit
c055f1d26f
1 changed files with 11 additions and 5 deletions
|
@ -8,7 +8,7 @@
|
||||||
# Thomas Huth <thuth@redhat.com>
|
# Thomas Huth <thuth@redhat.com>
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
from subprocess import check_call, run, DEVNULL
|
||||||
import tarfile
|
import tarfile
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
|
@ -25,12 +25,18 @@ def tar_extract(archive, dest_dir, member=None):
|
||||||
else:
|
else:
|
||||||
tf.extractall(path=dest_dir)
|
tf.extractall(path=dest_dir)
|
||||||
|
|
||||||
def cpio_extract(cpio_handle, output_path):
|
def cpio_extract(archive, output_path):
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
os.chdir(output_path)
|
os.chdir(output_path)
|
||||||
subprocess.run(['cpio', '-i'],
|
# Not passing 'check=True' as cpio exits with non-zero
|
||||||
input=cpio_handle.read(),
|
# status if the archive contains any device nodes :-(
|
||||||
stderr=subprocess.DEVNULL)
|
if type(archive) == str:
|
||||||
|
run(['cpio', '-i', '-F', archive],
|
||||||
|
stdout=DEVNULL, stderr=DEVNULL)
|
||||||
|
else:
|
||||||
|
run(['cpio', '-i'],
|
||||||
|
input=archive.read(),
|
||||||
|
stdout=DEVNULL, stderr=DEVNULL)
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
|
|
||||||
def zip_extract(archive, dest_dir, member=None):
|
def zip_extract(archive, dest_dir, member=None):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue