From 0449840ec3c693f1a2db6dc02b625a1d5fa0f1d4 Mon Sep 17 00:00:00 2001 From: deeplow Date: Tue, 5 Mar 2024 17:29:15 +0000 Subject: [PATCH] dz.ConvertDev: do not teleport .pyc files On Qubes the conversion in dev mode would fail when converting from a Fedora 38 development qube via a Fedora 39 disposable qube. The reason was that dz.ConvertDev was receiving `.pyc` files, which were compiled for python 3.11 but running on python 3.12. Unfortunately PyZipFile objects cannot send source python files, even though the documentation is a little bit unclear on this [1]. Fixes #723 [1]: https://docs.python.org/3/library/zipfile.html#pyzipfile-objects --- dangerzone/isolation_provider/qubes.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/dangerzone/isolation_provider/qubes.py b/dangerzone/isolation_provider/qubes.py index f0b96a9..0b607f8 100644 --- a/dangerzone/isolation_provider/qubes.py +++ b/dangerzone/isolation_provider/qubes.py @@ -80,16 +80,24 @@ class Qubes(IsolationProvider): def teleport_dz_module(self, wpipe: IO[bytes]) -> None: """Send the dangerzone module to another qube, as a zipfile.""" # Grab the absolute file path of the dangerzone module. - import dangerzone.conversion as _conv + import dangerzone as _dz - _conv_path = Path(inspect.getfile(_conv)).parent + _conv_path = Path(_dz.conversion.__file__).parent + _src_root = Path(_dz.__file__).parent.parent temp_file = io.BytesIO() - # Create a Python zipfile that contains all the files of the dangerzone module. - with zipfile.PyZipFile(temp_file, "w") as z: + with zipfile.ZipFile(temp_file, "w") as z: z.mkdir("dangerzone/") z.writestr("dangerzone/__init__.py", "") - z.writepy(str(_conv_path), basename="dangerzone/") + import dangerzone.conversion + + conv_path = Path(dangerzone.conversion.__file__).parent + for root, _, files in os.walk(_conv_path): + for file in files: + if file.endswith(".py"): + file_path = os.path.join(root, file) + relative_path = os.path.relpath(file_path, _src_root) + z.write(file_path, relative_path) # Send the following data: # 1. The size of the Python zipfile, so that the server can know when to