Fix bug that was preventing tor from connecting in snapcraft

This commit is contained in:
Micah Lee 2021-11-14 20:53:22 -08:00
parent f09bb66425
commit 99c85f55e2
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 27 additions and 11 deletions

View File

@ -437,6 +437,12 @@ class Common:
Returns True if OnionShare is running in a Flatpak sandbox
"""
return os.environ.get("FLATPAK_ID") == "org.onionshare.OnionShare"
def is_snapcraft(self):
"""
Returns True if OnionShare is running in a Flatpak sandbox
"""
return os.environ.get("SNAP_INSTANCE_NAME") == "onionshare"
@staticmethod
def random_string(num_bytes, output_len=None):

View File

@ -29,6 +29,7 @@ import subprocess
import time
import shlex
import psutil
import traceback
from distutils.version import LooseVersion as Version
@ -371,11 +372,16 @@ class Onion(object):
startupinfo=startupinfo,
)
else:
if self.common.is_snapcraft():
env = None
else:
env = {"LD_LIBRARY_PATH": os.path.dirname(self.tor_path)}
self.tor_proc = subprocess.Popen(
[self.tor_path, "-f", self.tor_torrc],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={"LD_LIBRARY_PATH": os.path.dirname(self.tor_path)},
env=env,
)
# Wait for the tor controller to start
@ -392,16 +398,20 @@ class Onion(object):
"connect",
"authenticating to tor controller",
)
# try:
if self.common.platform == "Windows" or self.common.platform == "Darwin":
self.c = Controller.from_port(port=self.tor_control_port)
self.c.authenticate()
else:
self.c = Controller.from_socket_file(path=self.tor_control_socket)
self.c.authenticate()
# except Exception as e:
# print("OnionShare could not connect to Tor:\n{}".format(e))
# raise BundledTorBroken(e.args[0])
try:
if (
self.common.platform == "Windows"
or self.common.platform == "Darwin"
):
self.c = Controller.from_port(port=self.tor_control_port)
self.c.authenticate()
else:
self.c = Controller.from_socket_file(path=self.tor_control_socket)
self.c.authenticate()
except Exception as e:
print("OnionShare could not connect to Tor:\n{}".format(e.args[0]))
print(traceback.format_exc())
raise BundledTorBroken(e.args[0])
while True:
try: