From ee98e1b0242c5cf1ae581ea50967b1127f9dc5a9 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Wed, 10 Dec 2014 00:50:19 +0000 Subject: [PATCH] removed helpers.get_tmp_dir() in favor of tempdir module --- onionshare/helpers.py | 15 ++------------- onionshare/onionshare.py | 4 ++-- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/onionshare/helpers.py b/onionshare/helpers.py index 210b9d29..08e6af26 100644 --- a/onionshare/helpers.py +++ b/onionshare/helpers.py @@ -17,7 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import os, inspect, hashlib, base64, hmac, platform, zipfile +import os, inspect, hashlib, base64, hmac, platform, zipfile, tempfile from itertools import izip # hack to make unicode filenames work (#141) @@ -94,23 +94,12 @@ def dir_size(start_path): return total_size -def get_tmp_dir(): - if get_platform() == "Windows": - if 'Temp' in os.environ: - temp = os.environ['Temp'].replace('\\', '/') - else: - temp = 'C:/tmp' - else: - temp = '/tmp' - return temp - - class ZipWriter(object): def __init__(self, zip_filename=None): if zip_filename: self.zip_filename = zip_filename else: - self.zip_filename = '{0}/onionshare_{1}.zip'.format(get_tmp_dir(), random_string(4, 6)) + self.zip_filename = '{0}/onionshare_{1}.zip'.format(tempfile.mkdtemp(), random_string(4, 6)) self.z = zipfile.ZipFile(self.zip_filename, 'w') diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index d7f13fb8..55917f16 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -17,7 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import os, sys, subprocess, time, argparse, inspect, shutil, socket, threading, urllib2 +import os, sys, subprocess, time, argparse, inspect, shutil, socket, threading, urllib2, tempfile import socks from stem.control import Controller @@ -118,7 +118,7 @@ class OnionShare(object): else: # come up with a hidden service directory name - self.hidserv_dir = '{0}/onionshare_{1}'.format(helpers.get_tmp_dir(), helpers.random_string(8)) + self.hidserv_dir = tempfile.mkdtemp() self.cleanup_filenames.append(self.hidserv_dir) # connect to the tor controlport