Make tor data dir always be a tempdir inside OnionShare's data dir

This commit is contained in:
Micah Lee 2018-11-25 17:17:56 -08:00
parent 66e50c96b8
commit 4934032144
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
3 changed files with 20 additions and 20 deletions

View File

@ -123,6 +123,23 @@ class Common(object):
return (tor_path, tor_geo_ip_file_path, tor_geo_ipv6_file_path, obfs4proxy_file_path)
def build_data_dir(self):
"""
Returns the path of the OnionShare data directory.
"""
if self.platform == 'Windows':
try:
appdata = os.environ['APPDATA']
return '{}\\OnionShare'.format(appdata)
except:
# If for some reason we don't have the 'APPDATA' environment variable
# (like running tests in Linux while pretending to be in Windows)
return os.path.expanduser('~/.config/onionshare')
elif self.platform == 'Darwin':
return os.path.expanduser('~/Library/Application Support/OnionShare')
else:
return os.path.expanduser('~/.config/onionshare')
def build_slug(self):
"""
Returns a random string made from two words from the wordlist, such as "deter-trig".

View File

@ -166,13 +166,8 @@ class Onion(object):
raise BundledTorNotSupported(strings._('settings_error_bundled_tor_not_supported'))
# Create a torrc for this session
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)
self.common.log('Onion', 'connect', 'tor_data_directory={}'.format(self.tor_data_directory.name))
else:
self.tor_data_directory = tempfile.TemporaryDirectory()
self.tor_data_directory = tempfile.TemporaryDirectory(dir=self.common.build_data_dir())
self.common.log('Onion', 'connect', 'tor_data_directory={}'.format(self.tor_data_directory.name))
# Create the torrc
with open(self.common.get_resource_path('torrc_template')) as f:

View File

@ -120,19 +120,7 @@ class Settings(object):
"""
Returns the path of the settings file.
"""
p = platform.system()
if p == 'Windows':
try:
appdata = os.environ['APPDATA']
return '{}\\OnionShare\\onionshare.json'.format(appdata)
except:
# If for some reason we don't have the 'APPDATA' environment variable
# (like running tests in Linux while pretending to be in Windows)
return os.path.expanduser('~/.config/onionshare/onionshare.json')
elif p == 'Darwin':
return os.path.expanduser('~/Library/Application Support/OnionShare/onionshare.json')
else:
return os.path.expanduser('~/.config/onionshare/onionshare.json')
return os.path.join(self.common.build_data_dir(), 'onionshare.json')
def build_default_downloads_dir(self):
"""