Skip to content

Commit

Permalink
Correct listing of a walled-off symbolic link (fixing sc0tfree#19), a…
Browse files Browse the repository at this point in the history
…nd correct a problem in this branch with processing subdirectories
  • Loading branch information
adeutscher committed Feb 25, 2020
1 parent d55890b commit 5dec63d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion updog/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def home(path):
if os.path.exists(requested_path):
# Read the files
try:
directory_files = process_files(os.scandir(requested_path), base_directory)
directory_files = process_files(os.scandir(requested_path), base_directory, requested_path)
except PermissionError:
abort(403, 'Read Permission Denied: ' + requested_path)

Expand Down
27 changes: 16 additions & 11 deletions updog/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,42 @@ def human_readable_file_size(size):
return '{:.4g} {}'.format(size / (1 << (order * 10)), _suffixes[order])


def process_files(directory_files, base_directory):
def process_files(directory_files, base_directory, requested_path):
files = []

for file_entry in directory_files:

real_path = os.path.realpath(os.path.join(base_directory, file_entry.name))
path = os.path.join(requested_path, file_entry.name)

# Default values for display/sort fields

# Default size
# Size
size = '--'
size_sort = -1

if os.path.isfile(real_path):
# Item is a file or a symlink points to a real file
size_sort = file_entry.stat().st_size
size = human_readable_file_size(size_sort)

# Last-Modified date
last_modified = '???'
last_modified_sort = -1
if os.path.exists(real_path):

if os.path.exists(path):
last_modified_sort = file_entry.stat().st_mtime
last_modified = ctime(last_modified_sort)

if os.path.isfile(path):
# Existing item is a file or a symlink points to a real file
size_sort = file_entry.stat().st_size
size = human_readable_file_size(size_sort)

files.append({
'name': file_entry.name,
'is_dir': file_entry.is_dir(),
'is_dir': os.path.isdir(path),
'rel_path': get_relative_path(file_entry.path, base_directory),
'size': size,
'size_sort': size_sort,
'last_modified': last_modified,
'last_modified_sort': last_modified_sort,
'is_symlink': file_entry.is_symlink(),
'exists': os.path.exists(real_path)
'exists': os.path.exists(path)
})
return files

Expand Down

0 comments on commit 5dec63d

Please sign in to comment.