mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-02 14:36:15 -04:00
Merge pull request #1345 from micahflee/1275_fix_website_mode
Fix website mode in Windows
This commit is contained in:
commit
5fab2e0396
1 changed files with 26 additions and 8 deletions
|
@ -55,6 +55,15 @@ class SendBaseModeWeb:
|
||||||
self.define_routes()
|
self.define_routes()
|
||||||
self.init()
|
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):
|
def set_file_info(self, filenames, processed_size_callback=None):
|
||||||
"""
|
"""
|
||||||
Build a data structure that describes the list of files
|
Build a data structure that describes the list of files
|
||||||
|
@ -75,34 +84,43 @@ class SendBaseModeWeb:
|
||||||
self.gzip_individual_files = {}
|
self.gzip_individual_files = {}
|
||||||
self.init()
|
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
|
# Build the file list
|
||||||
for filename in filenames:
|
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 it's a filename, add it
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
self.files[basename] = filename
|
self.files[self.fix_windows_paths(basename)] = filename
|
||||||
self.root_files[basename] = filename
|
self.root_files[self.fix_windows_paths(basename)] = filename
|
||||||
|
|
||||||
# If it's a directory, add it recursively
|
# If it's a directory, add it recursively
|
||||||
elif os.path.isdir(filename):
|
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):
|
for root, _, nested_filenames in os.walk(filename):
|
||||||
# Normalize the root path. So if the directory name is "/home/user/Documents/some_folder",
|
# 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".
|
# and it has a nested folder foobar, the root is "/home/user/Documents/some_folder/foobar".
|
||||||
# The normalized_root should be "some_folder/foobar"
|
# The normalized_root should be "some_folder/foobar"
|
||||||
normalized_root = os.path.join(
|
normalized_root = os.path.join(
|
||||||
basename, root[len(filename) :].lstrip("/")
|
basename, root[len(filename) :].lstrip(slash)
|
||||||
).rstrip("/")
|
).rstrip(slash)
|
||||||
|
|
||||||
# Add the dir itself
|
# Add the dir itself
|
||||||
self.files[normalized_root] = root
|
self.files[self.fix_windows_paths(normalized_root)] = root
|
||||||
|
|
||||||
# Add the files in this dir
|
# Add the files in this dir
|
||||||
for nested_filename in nested_filenames:
|
for nested_filename in nested_filenames:
|
||||||
self.files[
|
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)
|
] = os.path.join(root, nested_filename)
|
||||||
|
|
||||||
self.set_file_info_custom(filenames, processed_size_callback)
|
self.set_file_info_custom(filenames, processed_size_callback)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue