summaryrefslogtreecommitdiff
path: root/onionshare
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2019-09-03 20:52:49 -0700
committerMicah Lee <micah@micahflee.com>2019-09-03 20:52:59 -0700
commitc55925c1ce296ec8fe31bbe1b50c23133eda687a (patch)
tree0d60fec9d3132f15bfdd51be8409cc68bc5fd140 /onionshare
parent09f2f572982f39a411ae82891d677d929c29a52f (diff)
downloadonionshare-c55925c1ce296ec8fe31bbe1b50c23133eda687a.tar.gz
onionshare-c55925c1ce296ec8fe31bbe1b50c23133eda687a.zip
Make it so all of the state variables, including self.file_info get reset in SendBaseModeWEeb.set_file_info, which fixes the bug where old files you were sharing would end up in new zip files
Diffstat (limited to 'onionshare')
-rw-r--r--onionshare/web/send_base_mode.py146
-rw-r--r--onionshare/web/share_mode.py1
-rw-r--r--onionshare/web/website_mode.py2
3 files changed, 69 insertions, 80 deletions
diff --git a/onionshare/web/send_base_mode.py b/onionshare/web/send_base_mode.py
index 88dbd008..a34aedfd 100644
--- a/onionshare/web/send_base_mode.py
+++ b/onionshare/web/send_base_mode.py
@@ -18,7 +18,6 @@ class SendBaseModeWeb:
self.web = web
# Information about the file to be shared
- self.file_info = []
self.is_zipped = False
self.download_filename = None
self.download_filesize = None
@@ -26,17 +25,6 @@ class SendBaseModeWeb:
self.gzip_filesize = None
self.zip_writer = None
- # Dictionary mapping file paths to filenames on disk
- self.files = {}
- # This is only the root files and dirs, as opposed to all of them
- self.root_files = {}
-
- self.cleanup_filenames = []
- self.file_info = {'files': [], 'dirs': []}
-
- self.visit_count = 0
- self.download_count = 0
-
# If "Stop After First Download" is checked (stay_open == False), only allow
# one download at a time.
self.download_in_progress = False
@@ -44,78 +32,24 @@ class SendBaseModeWeb:
self.define_routes()
self.init()
- def init(self):
- """
- Inherited class will implement this
- """
- pass
-
- def define_routes(self):
- """
- Inherited class will implement this
- """
- pass
-
- def directory_listing_template(self):
- """
- Inherited class will implement this. It should call render_template and return
- the response.
- """
- pass
-
- def directory_listing(self, filenames, path='', filesystem_path=None):
- # If filesystem_path is None, this is the root directory listing
- files, dirs = self.build_directory_listing(filenames, filesystem_path)
- r = self.directory_listing_template(path, files, dirs)
- return self.web.add_security_headers(r)
-
- def build_directory_listing(self, filenames, filesystem_path):
- files = []
- dirs = []
-
- for filename in filenames:
- if filesystem_path:
- this_filesystem_path = os.path.join(filesystem_path, filename)
- else:
- this_filesystem_path = self.files[filename]
-
- is_dir = os.path.isdir(this_filesystem_path)
-
- if is_dir:
- dirs.append({
- 'basename': filename
- })
- else:
- size = os.path.getsize(this_filesystem_path)
- size_human = self.common.human_readable_filesize(size)
- files.append({
- 'basename': filename,
- 'size_human': size_human
- })
- return files, dirs
-
- def set_file_info_custom(self, filenames, processed_size_callback):
- """
- Inherited class will implement this.
- """
- pass
-
def set_file_info(self, filenames, processed_size_callback=None):
"""
Build a data structure that describes the list of files
"""
-
# If there's just one folder, replace filenames with a list of files inside that folder
if len(filenames) == 1 and os.path.isdir(filenames[0]):
filenames = [os.path.join(filenames[0], x) for x in os.listdir(filenames[0])]
# Re-initialize
+ self.files = {} # Dictionary mapping file paths to filenames on disk
+ self.root_files = {} # This is only the root files and dirs, as opposed to all of them
+ self.cleanup_filenames = []
+ self.visit_count = 0
+ self.download_count = 0
+ self.file_info = {'files': [], 'dirs': []}
+ self.gzip_individual_files = {}
self.init()
- # Clear the list of files
- self.files = {}
- self.root_files = {}
-
# Build the file list
for filename in filenames:
basename = os.path.basename(filename.rstrip('/'))
@@ -144,11 +78,36 @@ class SendBaseModeWeb:
self.set_file_info_custom(filenames, processed_size_callback)
- def render_logic(self, path=''):
- """
- Inherited class will implement this.
- """
- pass
+ def directory_listing(self, filenames, path='', filesystem_path=None):
+ # If filesystem_path is None, this is the root directory listing
+ files, dirs = self.build_directory_listing(filenames, filesystem_path)
+ r = self.directory_listing_template(path, files, dirs)
+ return self.web.add_security_headers(r)
+
+ def build_directory_listing(self, filenames, filesystem_path):
+ files = []
+ dirs = []
+
+ for filename in filenames:
+ if filesystem_path:
+ this_filesystem_path = os.path.join(filesystem_path, filename)
+ else:
+ this_filesystem_path = self.files[filename]
+
+ is_dir = os.path.isdir(this_filesystem_path)
+
+ if is_dir:
+ dirs.append({
+ 'basename': filename
+ })
+ else:
+ size = os.path.getsize(this_filesystem_path)
+ size_human = self.common.human_readable_filesize(size)
+ files.append({
+ 'basename': filename,
+ 'size_human': size_human
+ })
+ return files, dirs
def stream_individual_file(self, filesystem_path):
"""
@@ -260,3 +219,34 @@ class SendBaseModeWeb:
bytes_processed += blocksize
output_file.close()
+
+ def init(self):
+ """
+ Inherited class will implement this
+ """
+ pass
+
+ def define_routes(self):
+ """
+ Inherited class will implement this
+ """
+ pass
+
+ def directory_listing_template(self):
+ """
+ Inherited class will implement this. It should call render_template and return
+ the response.
+ """
+ pass
+
+ def set_file_info_custom(self, filenames, processed_size_callback):
+ """
+ Inherited class will implement this.
+ """
+ pass
+
+ def render_logic(self, path=''):
+ """
+ Inherited class will implement this.
+ """
+ pass \ No newline at end of file
diff --git a/onionshare/web/share_mode.py b/onionshare/web/share_mode.py
index 07cf0548..60620e2a 100644
--- a/onionshare/web/share_mode.py
+++ b/onionshare/web/share_mode.py
@@ -18,7 +18,6 @@ class ShareModeWeb(SendBaseModeWeb):
# Allow downloading individual files if "Stop sharing after files have been sent" is unchecked
self.download_individual_files = not self.common.settings.get('close_after_first_download')
- self.gzip_individual_files = {}
def define_routes(self):
"""
diff --git a/onionshare/web/website_mode.py b/onionshare/web/website_mode.py
index e409e7be..28f2607d 100644
--- a/onionshare/web/website_mode.py
+++ b/onionshare/web/website_mode.py
@@ -13,7 +13,7 @@ class WebsiteModeWeb(SendBaseModeWeb):
All of the web logic for website mode
"""
def init(self):
- self.gzip_individual_files = {}
+ pass
def define_routes(self):
"""