Hardcoded file path separators

This commit is contained in:
Karel Picman 2018-03-27 13:02:16 +02:00
parent 86a342d990
commit 1f95122829
2 changed files with 8 additions and 5 deletions

View File

@ -157,7 +157,7 @@ class DmsfController < ApplicationController
render_404 #and return render_404 #and return
rescue DmsfAccessError rescue DmsfAccessError
render_403 # and return render_403 # and return
rescue Exception => e rescue StandardError => e
flash[:error] = e.message flash[:error] = e.message
Rails.logger.error e.message Rails.logger.error e.message
end end
@ -423,7 +423,7 @@ class DmsfController < ApplicationController
:filename => filename_for_content_disposition("#{@project.name}-#{DateTime.now.strftime('%y%m%d%H%M%S')}.zip"), :filename => filename_for_content_disposition("#{@project.name}-#{DateTime.now.strftime('%y%m%d%H%M%S')}.zip"),
:type => 'application/zip', :type => 'application/zip',
:disposition => 'attachment') :disposition => 'attachment')
rescue Exception rescue StandardError
raise raise
ensure ensure
zip.close if zip zip.close if zip
@ -447,7 +447,7 @@ class DmsfController < ApplicationController
unless (file.project == @project) || User.current.allowed_to?(:view_dmsf_files, file.project) unless (file.project == @project) || User.current.allowed_to?(:view_dmsf_files, file.project)
raise DmsfAccessError raise DmsfAccessError
end end
zip.add_file(file, member, (file.dmsf_folder.dmsf_path_str if file.dmsf_folder)) if file zip.add_file(file, member, (file.dmsf_folder.dmsf_path_str if file.dmsf_folder))
end end
max_files = Setting.plugin_redmine_dmsf['dmsf_max_file_download'].to_i max_files = Setting.plugin_redmine_dmsf['dmsf_max_file_download'].to_i
if max_files > 0 && zip.files.length > max_files if max_files > 0 && zip.files.length > max_files

View File

@ -43,7 +43,10 @@ class DmsfZip
def add_file(file, member, root_path = nil) def add_file(file, member, root_path = nil)
unless @files.include?(file) unless @files.include?(file)
string_path = file.dmsf_folder.nil? ? '' : "#{file.dmsf_folder.dmsf_path_str}/" unless file && file.last_revision && File.exist?(file.last_revision.disk_file)
raise FileNotFound
end
string_path = file.dmsf_folder.nil? ? '' : (file.dmsf_folder.dmsf_path_str + File::SEPARATOR)
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
if member && !member.dmsf_title_format.nil? && !member.dmsf_title_format.empty? if member && !member.dmsf_title_format.nil? && !member.dmsf_title_format.empty?
string_path += file.formatted_name(member.dmsf_title_format) string_path += file.formatted_name(member.dmsf_title_format)
@ -64,7 +67,7 @@ class DmsfZip
def add_folder(folder, member, root_path = nil) def add_folder(folder, member, root_path = nil)
unless @folders.include?(folder) unless @folders.include?(folder)
string_path = "#{folder.dmsf_path_str}/" string_path = folder.dmsf_path_str + File::SEPARATOR
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
zip_entry = ::Zip::Entry.new(@zip_file, string_path, nil, nil, nil, nil, nil, nil, zip_entry = ::Zip::Entry.new(@zip_file, string_path, nil, nil, nil, nil, nil, nil,
::Zip::DOSTime.at(folder.modified)) ::Zip::DOSTime.at(folder.modified))