From d8b873a20825404ea8b9c6727680911b2e19e910 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 25 Nov 2018 16:15:27 -0800 Subject: [PATCH] Create a group container for macOS sandbox, and on Mac put the Tor data dir in it --- install/macos_sandbox/parent.plist | 6 ++++++ onionshare/onion.py | 7 ++++++- onionshare/settings.py | 6 +----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/install/macos_sandbox/parent.plist b/install/macos_sandbox/parent.plist index ceecd30a..6d557cf0 100644 --- a/install/macos_sandbox/parent.plist +++ b/install/macos_sandbox/parent.plist @@ -4,6 +4,8 @@ com.apple.security.app-sandbox + com.apple.security.network.server + com.apple.security.network.client com.apple.security.files.user-selected.read-only @@ -12,5 +14,9 @@ /OnionShare + com.apple.security.application-groups + + com.micahflee.onionshare + diff --git a/onionshare/onion.py b/onionshare/onion.py index 6066f059..f9f551c4 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -166,7 +166,12 @@ class Onion(object): raise BundledTorNotSupported(strings._('settings_error_bundled_tor_not_supported')) # Create a torrc for this session - self.tor_data_directory = tempfile.TemporaryDirectory() + if self.common.platform == 'Darwin': + group_container_dir = os.path.expanduser('~/Library/Group Containers/com.micahflee.onionshare') + os.makedirs(group_container_dir, exist_ok=True) + self.tor_data_directory = tempfile.TemporaryDirectory(dir=group_container_dir) + else: + self.tor_data_directory = tempfile.TemporaryDirectory() if self.common.platform == 'Windows': # Windows needs to use network ports, doesn't support unix sockets diff --git a/onionshare/settings.py b/onionshare/settings.py index ed827cbd..4a056989 100644 --- a/onionshare/settings.py +++ b/onionshare/settings.py @@ -163,11 +163,7 @@ class Settings(object): Save settings to file. """ self.common.log('Settings', 'save') - - try: - os.makedirs(os.path.dirname(self.filename)) - except: - pass + os.makedirs(os.path.dirname(self.filename), exist_ok=True) open(self.filename, 'w').write(json.dumps(self._settings)) self.common.log('Settings', 'save', 'Settings saved in {}'.format(self.filename))