mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 10:12:38 +02:00
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:
parent
297feab63d
commit
0449840ec3
1 changed files with 13 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue