Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions apps/dashboard/app/models/posix_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def files_to_zip
PATHS_TO_FILTER.include?(p.basename.to_s)
end.select do |path|
AllowlistPolicy.default.permitted?(path.realpath.to_s)
rescue StandardError
false
end.map do |path|
FileToZip.new(path.to_s, path.relative_path_from(expanded).to_s, path.realpath.to_s)
end
Expand Down Expand Up @@ -175,22 +177,20 @@ def can_download_as_zip?(timeout: Configuration.file_download_dir_timeout, downl
# Catch SIGTERM.
if s.exitstatus == 124
error = I18n.t('dashboard.files_directory_size_calculation_timeout')
elsif ! s.success?
elsif !(s.success? || s.exitstatus == 1) # du exits with status 1 if it encounters a broken symlink
error = I18n.t('dashboard.files_directory_size_unknown', exit_code: s.exitstatus, error: e)
else
# Example output from: du -cbs $path
# Example output from: du -cbLs $path
#
# 496184 .
# 64 ./ood-portal-generator/lib/ood_portal_generator
# 72 ./ood-portal-generator/lib
# 24 ./ood-portal-generator/templates
# 40 ./ood-portal-generator/share
# 576 ./ood-portal-generator
# 496184 $path
# 496184 total
#
size = o&.split&.first

if size.blank?
error = I18n.t('dashboard.files_directory_size_calculation_error')
elsif s.exitstatus == 1 && size.to_i.to_s != size # du may have been successful, check if size really is an integer
error = I18n.t('dashboard.files_directory_size_unknown', exit_code: s.exitstatus, error: e)
elsif size.to_i > download_directory_size_limit
error = I18n.t('dashboard.files_directory_too_large', download_directory_size_limit: download_directory_size_limit)
else
Expand Down
7 changes: 7 additions & 0 deletions apps/dashboard/test/models/files_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ class FilesTest < ActiveSupport::TestCase
end
end

test 'can_download_as_zip handles broken symlinks' do
Dir.mktmpdir do |dir|
File.symlink(File.join(dir, 'missing_file'), File.join(dir, 'link_to_missing_file'))
assert_equal [true, nil], PosixFile.new(dir).can_download_as_zip?
end
end

test "can_download_as_zip handles directory size exceeding limit" do
download_directory_size_limit = Configuration.file_download_dir_max
Dir.mktmpdir do |dir|
Expand Down