Skip to content

Commit

Permalink
Fix file comparisons on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
beavailable committed Mar 28, 2022
1 parent e614cd7 commit 44e64c1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions share.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,11 @@ def build_html(self, path, dirs, files):
builder.end_body()
return builder.build()

def cmp_path(self, s1, s2):
def cmp_file(self, e1, e2):
s1, hidden1, _ = e1
s2, hidden2, _ = e2
if hidden1 != hidden2:
return hidden2 - hidden1
if s1[0] == '.' and s2[0] != '.':
return -1
if s1[0] != '.' and s2[0] == '.':
Expand Down Expand Up @@ -593,7 +597,7 @@ def do_get(self):
except FileNotFoundError:
continue
files.append((os.path.basename(f), self.is_hidden(f), size))
files.sort(key=functools.cmp_to_key(lambda s1, s2: self.cmp_path(s1[0], s2[0])))
files.sort(key=functools.cmp_to_key(self.cmp_file))
self.respond_ok(self.build_html(path, [], files))
return
path = path[1:]
Expand Down Expand Up @@ -627,8 +631,8 @@ def do_get(self):
if os.path.isdir(file_path):
try:
dirs, files = self.list_dir(file_path)
dirs.sort(key=functools.cmp_to_key(lambda s1, s2: self.cmp_path(s1[0], s2[0])))
files.sort(key=functools.cmp_to_key(lambda s1, s2: self.cmp_path(s1[0], s2[0])))
dirs.sort(key=functools.cmp_to_key(self.cmp_file))
files.sort(key=functools.cmp_to_key(self.cmp_file))
except PermissionError:
self.respond_forbidden()
except FileNotFoundError:
Expand Down

0 comments on commit 44e64c1

Please sign in to comment.