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
This commit is contained in:
deeplow 2024-03-05 17:29:15 +00:00
parent 297feab63d
commit 0449840ec3
No known key found for this signature in database
GPG key ID: 577982871529A52A

View file

@ -80,16 +80,24 @@ class Qubes(IsolationProvider):
def teleport_dz_module(self, wpipe: IO[bytes]) -> None: def teleport_dz_module(self, wpipe: IO[bytes]) -> None:
"""Send the dangerzone module to another qube, as a zipfile.""" """Send the dangerzone module to another qube, as a zipfile."""
# Grab the absolute file path of the dangerzone module. # 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() temp_file = io.BytesIO()
# Create a Python zipfile that contains all the files of the dangerzone module. with zipfile.ZipFile(temp_file, "w") as z:
with zipfile.PyZipFile(temp_file, "w") as z:
z.mkdir("dangerzone/") z.mkdir("dangerzone/")
z.writestr("dangerzone/__init__.py", "") 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: # Send the following data:
# 1. The size of the Python zipfile, so that the server can know when to # 1. The size of the Python zipfile, so that the server can know when to