From 34771e3ea9f050b3f8e4be4c7a6e3acda033dffb Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Tue, 4 May 2021 20:01:30 -0700 Subject: When building the self.files, use forward slashes instead of backslashes in Windows --- cli/onionshare_cli/web/send_base_mode.py | 37 +++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/cli/onionshare_cli/web/send_base_mode.py b/cli/onionshare_cli/web/send_base_mode.py index c7347347..742f6f75 100644 --- a/cli/onionshare_cli/web/send_base_mode.py +++ b/cli/onionshare_cli/web/send_base_mode.py @@ -55,6 +55,15 @@ class SendBaseModeWeb: self.define_routes() self.init() + def fix_windows_paths(self, path): + """ + If on Windows, replace backslashes with slashes + """ + if self.common.platform == "Windows": + return path.replace("\\", "/") + + return path + def set_file_info(self, filenames, processed_size_callback=None): """ Build a data structure that describes the list of files @@ -70,40 +79,48 @@ class SendBaseModeWeb: self.root_files = ( {} ) # This is only the root files and dirs, as opposed to all of them - self.cleanup_filenames = [] self.cur_history_id = 0 self.file_info = {"files": [], "dirs": []} self.gzip_individual_files = {} self.init() + # Windows paths use backslashes, but website paths use forward slashes. We have to + # make sure we're stripping the correct type of slash + if self.common.platform == "Windows": + slash = "\\" + else: + slash = "/" + # Build the file list for filename in filenames: - basename = os.path.basename(filename.rstrip("/")) + basename = os.path.basename(filename.rstrip(slash)) # If it's a filename, add it if os.path.isfile(filename): - self.files[basename] = filename - self.root_files[basename] = filename + self.files[self.fix_windows_paths(basename)] = filename + self.root_files[self.fix_windows_paths(basename)] = filename # If it's a directory, add it recursively elif os.path.isdir(filename): - self.root_files[basename] = filename + self.root_files[self.fix_windows_paths(basename)] = filename for root, _, nested_filenames in os.walk(filename): # Normalize the root path. So if the directory name is "/home/user/Documents/some_folder", # and it has a nested folder foobar, the root is "/home/user/Documents/some_folder/foobar". # The normalized_root should be "some_folder/foobar" normalized_root = os.path.join( - basename, root[len(filename) :].lstrip("/") - ).rstrip("/") + basename, root[len(filename) :].lstrip(slash) + ).rstrip(slash) # Add the dir itself - self.files[normalized_root] = root + self.files[self.fix_windows_paths(normalized_root)] = root # Add the files in this dir for nested_filename in nested_filenames: self.files[ - os.path.join(normalized_root, nested_filename) + self.fix_windows_paths( + os.path.join(normalized_root, nested_filename) + ) ] = os.path.join(root, nested_filename) self.set_file_info_custom(filenames, processed_size_callback) @@ -177,7 +194,7 @@ class SendBaseModeWeb: self.gzip_individual_files[filesystem_path] = gzip_filename # Make sure the gzip file gets cleaned up when onionshare stops - self.cleanup_filenames.append(gzip_filename) + self.web.cleanup_filenames.append(gzip_filename) file_to_download = self.gzip_individual_files[filesystem_path] filesize = os.path.getsize(self.gzip_individual_files[filesystem_path]) -- cgit v1.2.3-54-g00ecf From 366190254bcfcf8c7dd41721be1440d758295c62 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 6 May 2021 08:46:42 +1000 Subject: Update the LICENSE to reflect the current path to third party licenses --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index c2dde1d3..ed4e5238 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -(Note: Third-party licenses can be found under install/licenses/.) +(Note: Third-party licenses can be found under licenses/.) OnionShare Copyright (C) 2014-2021 Micah Lee, et al. -- cgit v1.2.3-54-g00ecf